OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Fast-forwards the current time for testing. | 56 // Fast-forwards the current time for testing. |
57 static void SetTimeDeltaForTesting(int days); | 57 static void SetTimeDeltaForTesting(int days); |
58 | 58 |
59 AppBannerDataFetcher(content::WebContents* web_contents, | 59 AppBannerDataFetcher(content::WebContents* web_contents, |
60 base::WeakPtr<Delegate> weak_delegate, | 60 base::WeakPtr<Delegate> weak_delegate, |
61 int ideal_icon_size); | 61 int ideal_icon_size); |
62 | 62 |
63 // Begins creating a banner for the URL being displayed by the Delegate's | 63 // Begins creating a banner for the URL being displayed by the Delegate's |
64 // WebContents. | 64 // WebContents. |
65 void Start(const GURL& validated_url); | 65 virtual void Start(const GURL& validated_url); |
66 | 66 |
67 // Stops the pipeline when any asynchronous calls return. | 67 // Stops the pipeline when any asynchronous calls return. |
68 void Cancel(); | 68 void Cancel(); |
69 | 69 |
70 // Replaces the WebContents that is being observed. | 70 // Replaces the WebContents that is being observed. |
71 void ReplaceWebContents(content::WebContents* web_contents); | 71 void ReplaceWebContents(content::WebContents* web_contents); |
72 | 72 |
73 // Adds an observer to the list. | 73 // Adds an observer to the list. |
74 void AddObserverForTesting(Observer* observer); | 74 void AddObserverForTesting(Observer* observer); |
75 | 75 |
76 // Removes an observer from the list. | 76 // Removes an observer from the list. |
77 void RemoveObserverForTesting(Observer* observer); | 77 void RemoveObserverForTesting(Observer* observer); |
78 | 78 |
79 // Returns whether or not the pipeline has been stopped. | 79 // Returns whether or not the pipeline has been stopped. |
80 bool is_active() { return is_active_; } | 80 bool is_active() { return is_active_; } |
81 | 81 |
| 82 // Returns whether or not the requesting site is responsive. Used only on |
| 83 // mobile. |
| 84 bool is_responsive() { return is_responsive_; } |
| 85 |
82 // Returns the URL that kicked off the banner data retrieval. | 86 // Returns the URL that kicked off the banner data retrieval. |
83 const GURL& validated_url() { return validated_url_; } | 87 const GURL& validated_url() { return validated_url_; } |
84 | 88 |
85 // WebContentsObserver overrides. | 89 // WebContentsObserver overrides. |
86 void WebContentsDestroyed() override; | 90 void WebContentsDestroyed() override; |
87 void DidNavigateMainFrame( | 91 void DidNavigateMainFrame( |
88 const content::LoadCommittedDetails& details, | 92 const content::LoadCommittedDetails& details, |
89 const content::FrameNavigateParams& params) override; | 93 const content::FrameNavigateParams& params) override; |
90 bool OnMessageReceived(const IPC::Message& message, | 94 bool OnMessageReceived(const IPC::Message& message, |
91 content::RenderFrameHost* render_frame_host) override; | 95 content::RenderFrameHost* render_frame_host) override; |
(...skipping 23 matching lines...) Expand all Loading... |
115 bool FetchIcon(const GURL& image_url); | 119 bool FetchIcon(const GURL& image_url); |
116 | 120 |
117 // Creates a banner for the app using the given |icon|. | 121 // Creates a banner for the app using the given |icon|. |
118 virtual infobars::InfoBar* CreateBanner(const SkBitmap* icon, | 122 virtual infobars::InfoBar* CreateBanner(const SkBitmap* icon, |
119 const base::string16& title); | 123 const base::string16& title); |
120 | 124 |
121 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 125 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
122 // metric being recorded. | 126 // metric being recorded. |
123 void RecordDidShowBanner(const std::string& event_name); | 127 void RecordDidShowBanner(const std::string& event_name); |
124 | 128 |
| 129 // Returns whether the fetcher is active and web contents have not been |
| 130 // closed. |
| 131 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
| 132 |
| 133 bool is_active_; |
| 134 bool is_responsive_; |
| 135 GURL validated_url_; |
| 136 |
125 private: | 137 private: |
126 // Callbacks for data retrieval. | 138 // Callbacks for data retrieval. |
127 void OnDidGetManifest(const content::Manifest& manifest); | 139 void OnDidGetManifest(const content::Manifest& manifest); |
128 void OnDidCheckHasServiceWorker(bool has_service_worker); | 140 void OnDidCheckHasServiceWorker(bool has_service_worker); |
129 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; | 141 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; |
130 | 142 |
131 // Shows a banner for the app, if the given |icon| is valid. | 143 // Shows a banner for the app, if the given |icon| is valid. |
132 virtual void ShowBanner(const SkBitmap* icon); | 144 virtual void ShowBanner(const SkBitmap* icon); |
133 | 145 |
134 // Record that the banner could be shown at this point, if the triggering | 146 // Record that the banner could be shown at this point, if the triggering |
135 // heuristic allowed. | 147 // heuristic allowed. |
136 void RecordCouldShowBanner(); | 148 void RecordCouldShowBanner(); |
137 | 149 |
138 // Returns whether the banner should be shown. | 150 // Returns whether the banner should be shown. |
139 bool CheckIfShouldShowBanner(); | 151 bool CheckIfShouldShowBanner(); |
140 | 152 |
141 // Returns whether the fetcher is active and web contents have not been | |
142 // closed. | |
143 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | |
144 | |
145 // Returns whether the given Manifest is following the requirements to show | 153 // Returns whether the given Manifest is following the requirements to show |
146 // a web app banner. | 154 // a web app banner. |
147 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 155 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
148 content::WebContents* web_contents); | 156 content::WebContents* web_contents); |
149 | 157 |
150 const int ideal_icon_size_; | 158 const int ideal_icon_size_; |
151 const base::WeakPtr<Delegate> weak_delegate_; | 159 const base::WeakPtr<Delegate> weak_delegate_; |
152 ObserverList<Observer> observer_list_; | 160 ObserverList<Observer> observer_list_; |
153 bool is_active_; | |
154 int event_request_id_; | 161 int event_request_id_; |
155 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; | 162 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; |
156 scoped_ptr<SkBitmap> app_icon_; | 163 scoped_ptr<SkBitmap> app_icon_; |
157 | 164 |
158 GURL validated_url_; | |
159 base::string16 app_title_; | 165 base::string16 app_title_; |
160 content::Manifest web_app_data_; | 166 content::Manifest web_app_data_; |
161 | 167 |
162 friend class AppBannerDataFetcherUnitTest; | 168 friend class AppBannerDataFetcherUnitTest; |
163 friend class base::RefCounted<AppBannerDataFetcher>; | 169 friend class base::RefCounted<AppBannerDataFetcher>; |
164 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 170 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
165 }; | 171 }; |
166 | 172 |
167 } // namespace banners | 173 } // namespace banners |
168 | 174 |
169 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 175 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
OLD | NEW |