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

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

Issue 2138973002: Initial CL for talking to the WebAPK server to generate WebAPK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_builder_impl22_no_content Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
7
8 #include <jni.h>
9 #include <memory>
10
11 #include "base/android/scoped_java_ref.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h"
16 #include "chrome/browser/android/shortcut_info.h"
17 #include "chrome/browser/net/file_downloader.h"
18 #include "net/url_request/url_fetcher_delegate.h"
19 #include "third_party/skia/include/core/SkBitmap.h"
20
21 namespace base {
22 class FilePath;
23 }
24
25 namespace content {
26 class BrowserContext;
27 }
28
29 namespace net {
30 class URLFetcher;
31 class URLRequestContextGetter;
32 }
33
34 namespace webapk {
35 class CreateWebApkRequest;
36 }
37
38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
39 // server, download it, and install it.
40 class WebApkInstaller : public net::URLFetcherDelegate {
41 public:
42 using FinishCallback = base::Callback<void(bool)>;
43
44 WebApkInstaller(const ShortcutInfo& shortcut_info,
45 const SkBitmap& shorcut_icon);
46 ~WebApkInstaller() override;
47
48 // Register JNI methods.
49 static bool Register(JNIEnv* env);
50
51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to
52 // Google Play to install the generated WebAPK. Calls |callback| after the
53 // request to install the WebAPK is sent to Google Play.
54 void InstallAsync(content::BrowserContext* browser_context,
55 const FinishCallback& callback);
56
57 // Same as InstallAsync() but uses the passed in |request_context_getter|.
58 void InstallAsyncWithURLRequestContextGetter(
59 net::URLRequestContextGetter* request_context_getter,
60 const FinishCallback& callback);
61
62 protected:
63 // Starts installation of the downloaded WebAPK. Returns whether the install
64 // could be started. The installation may still fail if true is returned.
65 // |file_path| is the file path that the WebAPK was downloaded to.
66 // |package_name| is the package name that the WebAPK should be installed at.
67 virtual bool StartDownloadedWebApkInstall(
68 JNIEnv* env,
69 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
70 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
71
72 private:
73 // net::URLFetcherDelegate:
74 void OnURLFetchComplete(const net::URLFetcher* source) override;
75
76 // Initializes |request_context_getter_| on UI thread.
77 void InitializeRequestContextGetterOnUIThread(
78 content::BrowserContext* browser_context);
79
80 // Sends request to WebAPK server to create WebAPK. During a successful
81 // request the WebAPK server responds with the URL of the generated WebAPK.
82 void SendCreateWebApkRequest();
83
84 // Called with the URL of generated WebAPK and the package name that the
85 // WebAPK should be installed at.
86 void OnGotWebApkDownloadUrl(const std::string& download_url,
87 const std::string& package_name);
88
89 // Called once the WebAPK has been downloaded. Installs the WebAPK if the
90 // download was successful.
91 // |file_path| is the file path that the WebAPK was downloaded to.
92 // |package_name| is the package name that the WebAPK should be installed at.
93 void OnWebApkDownloaded(const base::FilePath& file_path,
94 const std::string& package_name,
95 FileDownloader::Result result);
96
97 // Populates webapk::CreateWebApkRequest and returns it.
98 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest();
99
100 // Called when the request to the WebAPK server times out or when the WebAPK
101 // download times out.
102 void OnTimeout();
103
104 // Called when the request to install the WebAPK is sent to Google Play.
105 void OnSuccess();
106
107 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
108 // WebAPK creation and the WebAPK download. It does not track the
109 // WebAPK installation. OnFailure() is not called if the WebAPK could not be
110 // installed.
111 void OnFailure();
112
113 net::URLRequestContextGetter* request_context_getter_;
114
115 // Sends HTTP request to WebAPK server.
116 std::unique_ptr<net::URLFetcher> url_fetcher_;
117
118 // Downloads WebAPK.
119 std::unique_ptr<FileDownloader> downloader_;
120
121 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the
122 // download takes too long.
123 base::OneShotTimer timer_;
124
125 // Callback to call once WebApkInstaller succeeds or fails.
126 FinishCallback finish_callback_;
127
128 // Web Manifest info.
129 const ShortcutInfo shortcut_info_;
130
131 // WebAPK app icon.
132 const SkBitmap shortcut_icon_;
133
134 // WebAPK server URL.
135 GURL server_url_;
136
137 // Used to get |weak_ptr_| on the IO thread.
138 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_;
139
140 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
141 };
142
143 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk.proto ('k') | chrome/browser/android/webapk/webapk_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698