Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class BrowserContext; | 19 class BrowserContext; |
| 20 } | 20 } |
| 21 | 21 |
| 22 struct ShortcutInfo; | 22 struct ShortcutInfo; |
| 23 class SkBitmap; | 23 class SkBitmap; |
| 24 | 24 |
| 25 // A Java counterpart will be generated for this enum. | |
| 26 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.webapps | |
| 27 enum class WebApkInstallResult { | |
| 28 // For installs: this indicates that the WebAPK has been installed. | |
| 29 // For updates: this indicates that the update request has been sent to Google | |
| 30 // Play (or the Android OS in the case of the "unknown sources" flow). | |
| 31 INSTALLED = 0, | |
|
dominickn
2017/03/05 23:52:39
SUCCESS ("Install" is redundant)
| |
| 32 INSTALL_FAILED = 1, | |
|
dominickn
2017/03/05 23:52:40
FAILURE
| |
| 33 // An install was initiated but it timed out. We did not get a response from | |
| 34 // either Google Play (or the Android OS in the case of the "unknown sources" | |
| 35 // flow) so it is possible that the install will complete some time in the | |
| 36 // future. | |
| 37 INSTALL_PROBABLY_FAILED = 2 | |
|
dominickn
2017/03/05 23:52:39
TIMEOUT (you can add new result values in future f
pkotwicz
2017/03/12 21:11:48
I prefer keeping this as INSTALL_PROBABLY_FAILED.
dominickn
2017/03/13 03:22:23
I don't quite understand your reasoning - WebApkIn
pkotwicz
2017/03/14 22:38:57
I prefer keeping the PROBABLY_FAILURE because we w
dominickn
2017/03/14 23:25:19
I don't want to block on this. Please rename it to
pkotwicz
2017/03/14 23:43:29
Thanks!
| |
| 38 }; | |
| 39 | |
| 25 // Service which talks to Chrome WebAPK server and Google Play to generate a | 40 // Service which talks to Chrome WebAPK server and Google Play to generate a |
| 26 // WebAPK on the server, download it, and install it. | 41 // WebAPK on the server, download it, and install it. |
| 27 class WebApkInstallService : public KeyedService { | 42 class WebApkInstallService : public KeyedService { |
| 28 public: | 43 public: |
| 29 // Called when the creation/updating of a WebAPK is finished or failed. | 44 // Called when the creation/updating of a WebAPK is finished or failed. |
| 30 // Parameters: | 45 // Parameters: |
| 31 // - whether the process succeeds. | 46 // - whether the process succeeds. |
| 32 // - the package name of the WebAPK. | 47 // - the package name of the WebAPK. |
| 33 using FinishCallback = base::Callback<void(bool, const std::string&)>; | 48 using FinishCallback = |
| 49 base::Callback<void(WebApkInstallResult, const std::string&)>; | |
| 34 | 50 |
| 35 static WebApkInstallService* Get(content::BrowserContext* browser_context); | 51 static WebApkInstallService* Get(content::BrowserContext* browser_context); |
| 36 | 52 |
| 37 explicit WebApkInstallService(content::BrowserContext* browser_context); | 53 explicit WebApkInstallService(content::BrowserContext* browser_context); |
| 38 ~WebApkInstallService() override; | 54 ~WebApkInstallService() override; |
| 39 | 55 |
| 40 // Returns whether an install for |web_manifest_url| is in progress. | 56 // Returns whether an install for |web_manifest_url| is in progress. |
| 41 bool IsInstallInProgress(const GURL& web_manifest_url); | 57 bool IsInstallInProgress(const GURL& web_manifest_url); |
| 42 | 58 |
| 43 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to | 59 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 56 const std::string& webapk_package, | 72 const std::string& webapk_package, |
| 57 int webapk_version, | 73 int webapk_version, |
| 58 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 74 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 59 bool is_manifest_stale, | 75 bool is_manifest_stale, |
| 60 const FinishCallback& finish_callback); | 76 const FinishCallback& finish_callback); |
| 61 | 77 |
| 62 private: | 78 private: |
| 63 // Called once the install/update completed or failed. | 79 // Called once the install/update completed or failed. |
| 64 void OnFinishedInstall(const GURL& web_manifest_url, | 80 void OnFinishedInstall(const GURL& web_manifest_url, |
| 65 const FinishCallback& finish_callback, | 81 const FinishCallback& finish_callback, |
| 66 bool success, | 82 WebApkInstallResult result, |
| 67 const std::string& webapk_package_name); | 83 const std::string& webapk_package_name); |
| 68 | 84 |
| 69 content::BrowserContext* browser_context_; | 85 content::BrowserContext* browser_context_; |
| 70 | 86 |
| 71 // In progress installs. | 87 // In progress installs. |
| 72 std::set<GURL> installs_; | 88 std::set<GURL> installs_; |
| 73 | 89 |
| 74 // Used to get |weak_ptr_|. | 90 // Used to get |weak_ptr_|. |
| 75 base::WeakPtrFactory<WebApkInstallService> weak_ptr_factory_; | 91 base::WeakPtrFactory<WebApkInstallService> weak_ptr_factory_; |
| 76 | 92 |
| 77 DISALLOW_COPY_AND_ASSIGN(WebApkInstallService); | 93 DISALLOW_COPY_AND_ASSIGN(WebApkInstallService); |
| 78 }; | 94 }; |
| 79 | 95 |
| 80 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ | 96 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_ |
| OLD | NEW |