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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 bool FetchIcon(const GURL& image_url); | 116 bool FetchIcon(const GURL& image_url); |
117 | 117 |
118 // Creates a banner for the app using the given |icon|. | 118 // Creates a banner for the app using the given |icon|. |
119 virtual void ShowBanner(const SkBitmap* icon, | 119 virtual void ShowBanner(const SkBitmap* icon, |
120 const base::string16& title) = 0; | 120 const base::string16& title) = 0; |
121 | 121 |
122 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 122 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
123 // metric being recorded. | 123 // metric being recorded. |
124 void RecordDidShowBanner(const std::string& event_name); | 124 void RecordDidShowBanner(const std::string& event_name); |
125 | 125 |
| 126 // Returns whether the fetcher is active and web contents have not been |
| 127 // closed. |
| 128 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
| 129 |
| 130 virtual void HandleWebApp(content::WebContents* web_contents); |
| 131 |
| 132 GURL validated_url_; |
| 133 |
126 private: | 134 private: |
127 // Callbacks for data retrieval. | 135 // Callbacks for data retrieval. |
128 void OnDidGetManifest(const content::Manifest& manifest); | 136 void OnDidGetManifest(const content::Manifest& manifest); |
129 void OnDidCheckHasServiceWorker(bool has_service_worker); | 137 void OnDidCheckHasServiceWorker(bool has_service_worker); |
130 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; | 138 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; |
131 | 139 |
132 // Shows a banner for the app, if the given |icon| is valid. | 140 // Shows a banner for the app, if the given |icon| is valid. |
133 virtual void RequestShowBanner(const SkBitmap* icon); | 141 virtual void RequestShowBanner(const SkBitmap* icon); |
134 | 142 |
135 // Record that the banner could be shown at this point, if the triggering | 143 // Record that the banner could be shown at this point, if the triggering |
136 // heuristic allowed. | 144 // heuristic allowed. |
137 void RecordCouldShowBanner(); | 145 void RecordCouldShowBanner(); |
138 | 146 |
139 // Returns whether the banner should be shown. | 147 // Returns whether the banner should be shown. |
140 bool CheckIfShouldShowBanner(); | 148 bool CheckIfShouldShowBanner(); |
141 | 149 |
142 // Returns whether the fetcher is active and web contents have not been | |
143 // closed. | |
144 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | |
145 | |
146 // Returns whether the given Manifest is following the requirements to show | 150 // Returns whether the given Manifest is following the requirements to show |
147 // a web app banner. | 151 // a web app banner. |
148 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 152 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
149 content::WebContents* web_contents); | 153 content::WebContents* web_contents); |
150 | 154 |
151 const int ideal_icon_size_; | 155 const int ideal_icon_size_; |
152 const base::WeakPtr<Delegate> weak_delegate_; | 156 const base::WeakPtr<Delegate> weak_delegate_; |
153 base::ObserverList<Observer> observer_list_; | 157 base::ObserverList<Observer> observer_list_; |
154 bool is_active_; | 158 bool is_active_; |
155 int event_request_id_; | 159 int event_request_id_; |
156 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; | 160 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; |
157 scoped_ptr<SkBitmap> app_icon_; | 161 scoped_ptr<SkBitmap> app_icon_; |
158 | 162 |
159 GURL validated_url_; | |
160 base::string16 app_title_; | 163 base::string16 app_title_; |
161 content::Manifest web_app_data_; | 164 content::Manifest web_app_data_; |
162 | 165 |
163 friend class AppBannerDataFetcherUnitTest; | 166 friend class AppBannerDataFetcherUnitTest; |
164 friend class base::RefCounted<AppBannerDataFetcher>; | 167 friend class base::RefCounted<AppBannerDataFetcher>; |
165 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 168 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
166 }; | 169 }; |
167 | 170 |
168 } // namespace banners | 171 } // namespace banners |
169 | 172 |
170 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 173 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
OLD | NEW |