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

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_impl2 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_BUILDER_H_
6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
7
8 #include <jni.h>
9 #include <memory>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/timer/timer.h"
15 #include "chrome/browser/android/shortcut_info.h"
16 #include "chrome/browser/net/file_downloader.h"
17 #include "net/url_request/url_fetcher_delegate.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
19
20 namespace base {
21 class FilePath;
22 }
23
24 namespace content {
25 class BrowserContext;
26 }
27
28 namespace net {
29 class URLFetcher;
30 class URLRequestContextGetter;
31 }
32
33 namespace webapk {
34 class CreateWebApkRequest;
35 }
36
37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
38 // server, download it, and install it.
39 class WebApkInstaller : public net::URLFetcherDelegate {
40 public:
41 using FinishCallback = base::Callback<void(bool)>;
42
43 WebApkInstaller(content::BrowserContext* browser_context,
44 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(const FinishCallback& callback);
55
56 private:
57 // net::URLFetcherDelegate:
58 void OnURLFetchComplete(const net::URLFetcher* source) override;
59
60 // Initializes |request_context_getter_| on UI thread.
61 void InitializeRequestContextGetterOnUIThread();
62
63 // Sends request to WebAPK server to create WebAPK. During a successful
64 // request the WebAPK server responds with the URL of the generated WebAPK.
65 void SendCreateWebApkRequest();
66
67 // Called with the URL of generated WebAPK and the package name that the
68 // WebAPK should be installed at.
69 void OnGotWebApkDownloadUrl(const std::string& download_url,
70 const std::string& package_name);
71
72 // Called once the WebAPK has been downloaded. Installs the WebAPK if the
73 // download was successful.
74 // |file_path| is the file path that the WebAPK was downloaded to.
75 // |package_name| is the package name that the WebAPK should be installed at.
76 void OnWebApkDownloaded(const base::FilePath& file_path,
77 const std::string& package_name,
78 FileDownloader::Result result);
79
80 // Populates webapk::CreateWebApkRequest and returns it.
81 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest();
82
83 // Called when the request to the WebAPK server times out or when the WebAPK
84 // download times out.
85 void OnTimeout();
86
87 // Called when the request to install the WebAPK is sent to Google Play.
88 void OnSuccess();
89
90 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
91 // WebAPK creation and the WebAPK download. It does not track the
92 // WebAPK installation. OnFailure() is not called if the WebAPK could not be
93 // installed.
94 void OnFailure();
95
96 content::BrowserContext* browser_context_;
97 net::URLRequestContextGetter* request_context_getter_;
98
99 // Sends HTTP request to WebAPK server.
100 std::unique_ptr<net::URLFetcher> url_fetcher_;
101
102 // Downloads WebAPK.
103 std::unique_ptr<FileDownloader> downloader_;
104
105 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the
106 // download takes too long.
107 base::OneShotTimer timer_;
108
109 // Callback to call once WebApkInstaller succeeds or fails.
110 FinishCallback finish_callback_;
111
112 // Web Manifest info.
113 const ShortcutInfo shortcut_info_;
114
115 // WebAPK app icon.
116 const SkBitmap shortcut_icon_;
117
118 // WebAPK server URL.
119 GURL server_url_;
120
121 // Used to get |weak_ptr_| on the IO thread.
122 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_;
123
124 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
125 };
126
127 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698