Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/alternate_nav_url_fetcher.h

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/net/url_fetcher.h" 12 #include "content/public/common/url_fetcher_delegate.h"
13 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 16
17 class NavigationController; 17 class NavigationController;
18 18
19 namespace net {
20 class URLRequestStatus;
21 }
22
19 // Attempts to get the HEAD of a host name and displays an info bar if the 23 // Attempts to get the HEAD of a host name and displays an info bar if the
20 // request was successful. This is used for single-word queries where we can't 24 // request was successful. This is used for single-word queries where we can't
21 // tell if the entry was a search or an intranet hostname. The autocomplete bar 25 // tell if the entry was a search or an intranet hostname. The autocomplete bar
22 // assumes it's a query and issues an AlternateNavURLFetcher to display a "did 26 // assumes it's a query and issues an AlternateNavURLFetcher to display a "did
23 // you mean" infobar suggesting a navigation. 27 // you mean" infobar suggesting a navigation.
24 // 28 //
25 // The memory management of this object is a bit tricky. The location bar view 29 // The memory management of this object is a bit tricky. The location bar view
26 // will create us and be responsible for us until we attach as an observer 30 // will create us and be responsible for us until we attach as an observer
27 // after a pending load starts (it will delete us if this doesn't happen). 31 // after a pending load starts (it will delete us if this doesn't happen).
28 // Once this pending load starts, we're responsible for deleting ourselves. 32 // Once this pending load starts, we're responsible for deleting ourselves.
29 // We'll do this in the following cases: 33 // We'll do this in the following cases:
30 // * The tab is navigated again once we start listening (so the fetch is no 34 // * The tab is navigated again once we start listening (so the fetch is no
31 // longer useful) 35 // longer useful)
32 // * The tab is closed before we show an infobar 36 // * The tab is closed before we show an infobar
33 // * The intranet fetch fails 37 // * The intranet fetch fails
34 // * None of the above apply, so we successfully show an infobar 38 // * None of the above apply, so we successfully show an infobar
35 class AlternateNavURLFetcher : public content::NotificationObserver, 39 class AlternateNavURLFetcher : public content::NotificationObserver,
36 public URLFetcher::Delegate { 40 public content::URLFetcherDelegate {
37 public: 41 public:
38 enum State { 42 enum State {
39 NOT_STARTED, 43 NOT_STARTED,
40 IN_PROGRESS, 44 IN_PROGRESS,
41 SUCCEEDED, 45 SUCCEEDED,
42 FAILED, 46 FAILED,
43 }; 47 };
44 48
45 explicit AlternateNavURLFetcher(const GURL& alternate_nav_url); 49 explicit AlternateNavURLFetcher(const GURL& alternate_nav_url);
46 virtual ~AlternateNavURLFetcher(); 50 virtual ~AlternateNavURLFetcher();
47 51
48 State state() const { return state_; } 52 State state() const { return state_; }
49 53
50 private: 54 private:
51 // content::NotificationObserver 55 // content::NotificationObserver
52 virtual void Observe(int type, 56 virtual void Observe(int type,
53 const content::NotificationSource& source, 57 const content::NotificationSource& source,
54 const content::NotificationDetails& details) OVERRIDE; 58 const content::NotificationDetails& details) OVERRIDE;
55 59
56 // URLFetcher::Delegate 60 // content::URLFetcherDelegate
57 virtual void OnURLFetchComplete(const URLFetcher* source, 61 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
58 const GURL& url,
59 const net::URLRequestStatus& status,
60 int response_code,
61 const net::ResponseCookies& cookies,
62 const std::string& data) OVERRIDE;
63 62
64 // Sets |controller_| to the supplied pointer and begins fetching 63 // Sets |controller_| to the supplied pointer and begins fetching
65 // |alternate_nav_url_|. 64 // |alternate_nav_url_|.
66 void StartFetch(NavigationController* controller); 65 void StartFetch(NavigationController* controller);
67 66
68 // Sets |state_| to either SUCCEEDED or FAILED depending on the result of the 67 // Sets |state_| to either SUCCEEDED or FAILED depending on the result of the
69 // fetch. 68 // fetch.
70 void SetStatusFromURLFetch(const GURL& url, 69 void SetStatusFromURLFetch(const GURL& url,
71 const net::URLRequestStatus& status, 70 const net::URLRequestStatus& status,
72 int response_code); 71 int response_code);
73 72
74 // Displays the infobar if all conditions are met (the page has loaded and 73 // Displays the infobar if all conditions are met (the page has loaded and
75 // the fetch of the alternate URL succeeded). Unless we're still waiting on 74 // the fetch of the alternate URL succeeded). Unless we're still waiting on
76 // one of the above conditions to finish, this will also delete us, as whether 75 // one of the above conditions to finish, this will also delete us, as whether
77 // or not we show an infobar, there is no reason to live further. 76 // or not we show an infobar, there is no reason to live further.
78 void ShowInfobarIfPossible(); 77 void ShowInfobarIfPossible();
79 78
80 GURL alternate_nav_url_; 79 GURL alternate_nav_url_;
81 scoped_ptr<URLFetcher> fetcher_; 80 scoped_ptr<URLFetcher> fetcher_;
82 NavigationController* controller_; 81 NavigationController* controller_;
83 State state_; 82 State state_;
84 bool navigated_to_entry_; 83 bool navigated_to_entry_;
85 84
86 content::NotificationRegistrar registrar_; 85 content::NotificationRegistrar registrar_;
87 86
88 DISALLOW_COPY_AND_ASSIGN(AlternateNavURLFetcher); 87 DISALLOW_COPY_AND_ASSIGN(AlternateNavURLFetcher);
89 }; 88 };
90 89
91 #endif // CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_ 90 #endif // CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/alternate_nav_url_fetcher.cc » ('j') | chrome/browser/metrics/metrics_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698