Fixing build: GetViewContainer changed name from under me. :)
[chromium-blink-merge.git] / chrome / browser / alternate_nav_url_fetcher.h
blobb28b48f076efc0bc9af0797f1cb9e83c68c8c380
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_
6 #define CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_
8 #include <string>
10 #include "chrome/browser/url_fetcher.h"
11 #include "chrome/common/notification_registrar.h"
12 #include "chrome/common/notification_service.h"
14 class NavigationController;
16 // Attempts to get the HEAD of a host name and displays an info bar if the
17 // request was successful. This is used for single-word queries where we can't
18 // tell if the entry was a search or an intranet hostname. The autocomplete bar
19 // assumes it's a query and issues an AlternateNavURLFetcher to display a "did
20 // you mean" infobar suggesting a navigation.
22 // The memory management of this object is a bit tricky. The location bar view
23 // will create us and be responsible for us until we attach as an observer
24 // after a pending load starts (it will delete us if this doesn't happen).
25 // Once this pending load starts, we're responsible for deleting ourselves.
26 // We'll do this when the load commits, or when the navigation controller
27 // itself is deleted.
28 class AlternateNavURLFetcher : public NotificationObserver,
29 public URLFetcher::Delegate {
30 public:
31 enum State {
32 NOT_STARTED,
33 IN_PROGRESS,
34 SUCCEEDED,
35 FAILED,
38 explicit AlternateNavURLFetcher(const std::wstring& alternate_nav_url);
40 State state() const { return state_; }
42 // NotificationObserver
43 virtual void Observe(NotificationType type,
44 const NotificationSource& source,
45 const NotificationDetails& details);
47 // URLFetcher::Delegate
48 virtual void OnURLFetchComplete(const URLFetcher* source,
49 const GURL& url,
50 const URLRequestStatus& status,
51 int response_code,
52 const ResponseCookies& cookies,
53 const std::string& data);
55 private:
56 // Displays the infobar if all conditions are met (the page has loaded and
57 // the fetch of the alternate URL succeeded). If the infobar is displayed,
58 // this object is no longer necessary and this function WILL DELETE |this|!.
59 void ShowInfobarIfPossible();
61 std::wstring alternate_nav_url_;
62 scoped_ptr<URLFetcher> fetcher_;
63 NavigationController* controller_;
64 State state_;
65 bool navigated_to_entry_;
67 NotificationRegistrar registrar_;
69 DISALLOW_COPY_AND_ASSIGN(AlternateNavURLFetcher);
72 #endif // CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_