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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.h

Issue 2943913002: [Android WebAPK] Make webapk_installer.cc return proto as base64 string
Patch Set: Merge branch 'background_updates0_5' into background_updates00 Created 3 years, 6 months 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
OLDNEW
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_INSTALLER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <vector>
12 11
13 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
14 #include "base/callback.h" 13 #include "base/callback.h"
15 #include "base/macros.h" 14 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
18 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
19 #include "chrome/browser/android/shortcut_info.h" 18 #include "chrome/browser/android/shortcut_info.h"
20 #include "chrome/browser/android/webapk/webapk_install_service.h" 19 #include "chrome/browser/android/webapk/webapk_install_service.h"
21 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
(...skipping 22 matching lines...) Expand all
44 // APK to be installed. Calls |callback| once the install completed or failed. 43 // APK to be installed. Calls |callback| once the install completed or failed.
45 static void InstallAsync(content::BrowserContext* context, 44 static void InstallAsync(content::BrowserContext* context,
46 const ShortcutInfo& shortcut_info, 45 const ShortcutInfo& shortcut_info,
47 const SkBitmap& primary_icon, 46 const SkBitmap& primary_icon,
48 const SkBitmap& badge_icon, 47 const SkBitmap& badge_icon,
49 const FinishCallback& finish_callback); 48 const FinishCallback& finish_callback);
50 49
51 // Creates a self-owned WebApkInstaller instance and talks to the Chrome 50 // Creates a self-owned WebApkInstaller instance and talks to the Chrome
52 // WebAPK server to update a WebAPK on the server and locally requests the 51 // WebAPK server to update a WebAPK on the server and locally requests the
53 // APK to be installed. Calls |callback| once the install completed or failed. 52 // APK to be installed. Calls |callback| once the install completed or failed.
54 static void UpdateAsync( 53 static void UpdateAsync(content::BrowserContext* context,
55 content::BrowserContext* context, 54 const std::string& webapk_package,
56 const std::string& webapk_package, 55 const GURL& start_url,
57 const GURL& start_url, 56 const base::string16& short_name,
58 const base::string16& short_name, 57 std::unique_ptr<std::string> serialized_proto,
59 std::unique_ptr<std::vector<uint8_t>> serialized_proto, 58 const FinishCallback& callback);
60 const FinishCallback& callback);
61 59
62 // Calls the private function |InstallAsync| for testing. 60 // Calls the private function |InstallAsync| for testing.
63 // Should be used only for testing. 61 // Should be used only for testing.
64 static void InstallAsyncForTesting(WebApkInstaller* installer, 62 static void InstallAsyncForTesting(WebApkInstaller* installer,
65 const ShortcutInfo& shortcut_info, 63 const ShortcutInfo& shortcut_info,
66 const SkBitmap& primary_icon, 64 const SkBitmap& primary_icon,
67 const SkBitmap& badge_icon, 65 const SkBitmap& badge_icon,
68 const FinishCallback& finish_callback); 66 const FinishCallback& finish_callback);
69 67
70 // Calls the private function |UpdateAsync| for testing. 68 // Calls the private function |UpdateAsync| for testing.
71 // Should be used only for testing. 69 // Should be used only for testing.
72 static void UpdateAsyncForTesting( 70 static void UpdateAsyncForTesting(
73 WebApkInstaller* installer, 71 WebApkInstaller* installer,
74 const std::string& webapk_package, 72 const std::string& webapk_package,
75 const GURL& start_url, 73 const GURL& start_url,
76 const base::string16& short_name, 74 const base::string16& short_name,
77 std::unique_ptr<std::vector<uint8_t>> serialized_proto, 75 std::unique_ptr<std::string> serialized_proto,
78 const FinishCallback& callback); 76 const FinishCallback& callback);
79 77
80 // Sets the timeout for the server requests. 78 // Sets the timeout for the server requests.
81 void SetTimeoutMs(int timeout_ms); 79 void SetTimeoutMs(int timeout_ms);
82 80
83 // Called once the installation is complete or failed. 81 // Called once the installation is complete or failed.
84 void OnInstallFinished(JNIEnv* env, 82 void OnInstallFinished(JNIEnv* env,
85 const base::android::JavaParamRef<jobject>& obj, 83 const base::android::JavaParamRef<jobject>& obj,
86 jint result); 84 jint result);
87 85
88 // Asynchronously builds the WebAPK proto on a background thread for an update 86 // Asynchronously builds the WebAPK proto on a background thread for an update
89 // or install request. Runs |callback| on the calling thread when complete. 87 // or install request. Runs |callback| on the calling thread when complete.
90 static void BuildProto( 88 static void BuildProto(
91 const ShortcutInfo& shortcut_info, 89 const ShortcutInfo& shortcut_info,
92 const SkBitmap& primary_icon, 90 const SkBitmap& primary_icon,
93 const SkBitmap& badge_icon, 91 const SkBitmap& badge_icon,
94 const std::string& package_name, 92 const std::string& package_name,
95 const std::string& version, 93 const std::string& version,
96 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 94 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
97 bool is_manifest_stale, 95 bool is_manifest_stale,
98 const base::Callback<void(std::unique_ptr<std::vector<uint8_t>>)>& 96 const base::Callback<void(std::unique_ptr<std::string>)>& callback);
99 callback);
100 97
101 // Registers JNI hooks. 98 // Registers JNI hooks.
102 static bool Register(JNIEnv* env); 99 static bool Register(JNIEnv* env);
103 100
104 protected: 101 protected:
105 explicit WebApkInstaller(content::BrowserContext* browser_context); 102 explicit WebApkInstaller(content::BrowserContext* browser_context);
106 103
107 // Called when the package name of the WebAPK is available and the install 104 // Called when the package name of the WebAPK is available and the install
108 // or update request should be issued. 105 // or update request should be issued.
109 virtual void InstallOrUpdateWebApk(const std::string& package_name, 106 virtual void InstallOrUpdateWebApk(const std::string& package_name,
(...skipping 20 matching lines...) Expand all
130 const SkBitmap& primary_icon, 127 const SkBitmap& primary_icon,
131 const SkBitmap& badge_icon, 128 const SkBitmap& badge_icon,
132 const FinishCallback& finish_callback); 129 const FinishCallback& finish_callback);
133 130
134 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to 131 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to
135 // the Google Play server to install the downloaded WebAPK. Calls 132 // the Google Play server to install the downloaded WebAPK. Calls
136 // |finish_callback| once the update completed or failed. 133 // |finish_callback| once the update completed or failed.
137 void UpdateAsync(const std::string& webapk_package, 134 void UpdateAsync(const std::string& webapk_package,
138 const GURL& start_url, 135 const GURL& start_url,
139 const base::string16& short_name, 136 const base::string16& short_name,
140 const std::unique_ptr<std::vector<uint8_t>> serialized_proto, 137 const std::unique_ptr<std::string> serialized_proto,
141 const FinishCallback& callback); 138 const FinishCallback& callback);
142 139
143 // net::URLFetcherDelegate: 140 // net::URLFetcherDelegate:
144 void OnURLFetchComplete(const net::URLFetcher* source) override; 141 void OnURLFetchComplete(const net::URLFetcher* source) override;
145 142
146 // Called with the computed Murmur2 hash for the primary icon. 143 // Called with the computed Murmur2 hash for the primary icon.
147 void OnGotPrimaryIconMurmur2Hash(const std::string& primary_icon_hash); 144 void OnGotPrimaryIconMurmur2Hash(const std::string& primary_icon_hash);
148 145
149 // Called with the computed Murmur2 hash for the badge icon, and 146 // Called with the computed Murmur2 hash for the badge icon, and
150 // |did_fetch_badge_icon| to indicate whether there was an attempt to fetch 147 // |did_fetch_badge_icon| to indicate whether there was an attempt to fetch
151 // badge icon. 148 // badge icon.
152 void OnGotBadgeIconMurmur2Hash(bool did_fetch_badge_icon, 149 void OnGotBadgeIconMurmur2Hash(bool did_fetch_badge_icon,
153 const std::string& primary_icon_hash, 150 const std::string& primary_icon_hash,
154 const std::string& badge_icon_hash); 151 const std::string& badge_icon_hash);
155 152
156 // Sends a request to WebAPK server to create/update WebAPK. During a 153 // Sends a request to WebAPK server to create/update WebAPK. During a
157 // successful request the WebAPK server responds with a token to send to 154 // successful request the WebAPK server responds with a token to send to
158 // Google Play. 155 // Google Play.
159 void SendRequest(std::unique_ptr<std::vector<uint8_t>> serialized_proto); 156 void SendRequest(std::unique_ptr<std::string> serialized_proto);
160 157
161 net::URLRequestContextGetter* request_context_getter_; 158 net::URLRequestContextGetter* request_context_getter_;
162 159
163 // Sends HTTP request to WebAPK server. 160 // Sends HTTP request to WebAPK server.
164 std::unique_ptr<net::URLFetcher> url_fetcher_; 161 std::unique_ptr<net::URLFetcher> url_fetcher_;
165 162
166 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the 163 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the
167 // download takes too long. 164 // download takes too long.
168 base::OneShotTimer timer_; 165 base::OneShotTimer timer_;
169 166
(...skipping 29 matching lines...) Expand all
199 // Points to the Java Object. 196 // Points to the Java Object.
200 base::android::ScopedJavaGlobalRef<jobject> java_ref_; 197 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
201 198
202 // Used to get |weak_ptr_|. 199 // Used to get |weak_ptr_|.
203 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; 200 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_;
204 201
205 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 202 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
206 }; 203 };
207 204
208 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 205 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698