Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ |
| 6 #define CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ | 6 #define CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
| 14 #include "content/public/common/url_fetcher_delegate.h" | |
| 15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" | |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class NavigationController; | 18 class NavigationController; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 class URLFetcher; | |
|
wtc
2012/05/22 17:26:38
net/url_request/url_fetcher_delegate.h contains a
akalin
2012/05/22 21:07:05
I prefer to explicitly declare, unless the only us
| |
| 22 class URLRequestStatus; | 23 class URLRequestStatus; |
| 23 } | 24 } |
| 24 | 25 |
| 25 // Attempts to get the HEAD of a host name and displays an info bar if the | 26 // Attempts to get the HEAD of a host name and displays an info bar if the |
| 26 // request was successful. This is used for single-word queries where we can't | 27 // request was successful. This is used for single-word queries where we can't |
| 27 // tell if the entry was a search or an intranet hostname. The autocomplete bar | 28 // tell if the entry was a search or an intranet hostname. The autocomplete bar |
| 28 // assumes it's a query and issues an AlternateNavURLFetcher to display a "did | 29 // assumes it's a query and issues an AlternateNavURLFetcher to display a "did |
| 29 // you mean" infobar suggesting a navigation. | 30 // you mean" infobar suggesting a navigation. |
| 30 // | 31 // |
| 31 // The memory management of this object is a bit tricky. The location bar view | 32 // The memory management of this object is a bit tricky. The location bar view |
| 32 // will create us and be responsible for us until we attach as an observer | 33 // will create us and be responsible for us until we attach as an observer |
| 33 // after a pending load starts (it will delete us if this doesn't happen). | 34 // after a pending load starts (it will delete us if this doesn't happen). |
| 34 // Once this pending load starts, we're responsible for deleting ourselves. | 35 // Once this pending load starts, we're responsible for deleting ourselves. |
| 35 // We'll do this in the following cases: | 36 // We'll do this in the following cases: |
| 36 // * The tab is navigated again once we start listening (so the fetch is no | 37 // * The tab is navigated again once we start listening (so the fetch is no |
| 37 // longer useful) | 38 // longer useful) |
| 38 // * The tab is closed before we show an infobar | 39 // * The tab is closed before we show an infobar |
| 39 // * The intranet fetch fails | 40 // * The intranet fetch fails |
| 40 // * None of the above apply, so we successfully show an infobar | 41 // * None of the above apply, so we successfully show an infobar |
| 41 class AlternateNavURLFetcher : public content::NotificationObserver, | 42 class AlternateNavURLFetcher : public content::NotificationObserver, |
| 42 public content::URLFetcherDelegate { | 43 public net::URLFetcherDelegate { |
| 43 public: | 44 public: |
| 44 enum State { | 45 enum State { |
| 45 NOT_STARTED, | 46 NOT_STARTED, |
| 46 IN_PROGRESS, | 47 IN_PROGRESS, |
| 47 SUCCEEDED, | 48 SUCCEEDED, |
| 48 FAILED, | 49 FAILED, |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 explicit AlternateNavURLFetcher(const GURL& alternate_nav_url); | 52 explicit AlternateNavURLFetcher(const GURL& alternate_nav_url); |
| 52 virtual ~AlternateNavURLFetcher(); | 53 virtual ~AlternateNavURLFetcher(); |
| 53 | 54 |
| 54 State state() const { return state_; } | 55 State state() const { return state_; } |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 // content::NotificationObserver | 58 // content::NotificationObserver |
| 58 virtual void Observe(int type, | 59 virtual void Observe(int type, |
| 59 const content::NotificationSource& source, | 60 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) OVERRIDE; | 61 const content::NotificationDetails& details) OVERRIDE; |
| 61 | 62 |
| 62 // content::URLFetcherDelegate | 63 // net::URLFetcherDelegate |
| 63 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 64 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 64 | 65 |
| 65 // Sets |controller_| to the supplied pointer and begins fetching | 66 // Sets |controller_| to the supplied pointer and begins fetching |
| 66 // |alternate_nav_url_|. | 67 // |alternate_nav_url_|. |
| 67 void StartFetch(content::NavigationController* controller); | 68 void StartFetch(content::NavigationController* controller); |
| 68 | 69 |
| 69 // Sets |state_| to either SUCCEEDED or FAILED depending on the result of the | 70 // Sets |state_| to either SUCCEEDED or FAILED depending on the result of the |
| 70 // fetch. | 71 // fetch. |
| 71 void SetStatusFromURLFetch(const GURL& url, | 72 void SetStatusFromURLFetch(const GURL& url, |
| 72 const net::URLRequestStatus& status, | 73 const net::URLRequestStatus& status, |
| 73 int response_code); | 74 int response_code); |
| 74 | 75 |
| 75 // Displays the infobar if all conditions are met (the page has loaded and | 76 // Displays the infobar if all conditions are met (the page has loaded and |
| 76 // the fetch of the alternate URL succeeded). Unless we're still waiting on | 77 // the fetch of the alternate URL succeeded). Unless we're still waiting on |
| 77 // one of the above conditions to finish, this will also delete us, as whether | 78 // one of the above conditions to finish, this will also delete us, as whether |
| 78 // or not we show an infobar, there is no reason to live further. | 79 // or not we show an infobar, there is no reason to live further. |
| 79 void ShowInfobarIfPossible(); | 80 void ShowInfobarIfPossible(); |
| 80 | 81 |
| 81 GURL alternate_nav_url_; | 82 GURL alternate_nav_url_; |
| 82 scoped_ptr<content::URLFetcher> fetcher_; | 83 scoped_ptr<net::URLFetcher> fetcher_; |
|
wtc
2012/05/22 17:26:38
I guess your policy is that we should use net::URL
akalin
2012/05/22 21:07:05
Sure, although it'll be moot soon; I will remove c
| |
| 83 content::NavigationController* controller_; | 84 content::NavigationController* controller_; |
| 84 State state_; | 85 State state_; |
| 85 bool navigated_to_entry_; | 86 bool navigated_to_entry_; |
| 86 | 87 |
| 87 content::NotificationRegistrar registrar_; | 88 content::NotificationRegistrar registrar_; |
| 88 | 89 |
| 89 DISALLOW_COPY_AND_ASSIGN(AlternateNavURLFetcher); | 90 DISALLOW_COPY_AND_ASSIGN(AlternateNavURLFetcher); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 #endif // CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ | 93 #endif // CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ |
| OLD | NEW |