Chromium Code Reviews| Index: chrome/browser/android/webapk/manifest_upgrade_detector.h |
| diff --git a/chrome/browser/android/webapk/manifest_upgrade_detector.h b/chrome/browser/android/webapk/manifest_upgrade_detector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..00f6f3caad413c7553c218ae8ffbd4bdb7866cb2 |
| --- /dev/null |
| +++ b/chrome/browser/android/webapk/manifest_upgrade_detector.h |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_H_ |
| +#define CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_H_ |
| + |
| +#include <vector> |
|
pkotwicz
2016/07/20 20:57:04
Nit: This include is unnecessary
Xi Han
2016/07/22 17:13:11
Removed.
|
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_weak_ref.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| + |
| +namespace content { |
| +struct Manifest; |
| +class WebContents; |
| +} |
| + |
| +class GURL; |
| +struct ShortcutInfo; |
| + |
| +// ManifestUpgradeDetector is the C++ counterpart of |
| +// org.chromium.chrome.browser's ManifestUpgradeDetector in Java. It is created |
| +// via a JNI (Initialize) call and MUST BE DESTROYED via Destroy(). |
| +class ManifestUpgradeDetector : public content::WebContentsObserver { |
| + public: |
| + enum ErrorCode { |
| + NoErrorDetected, |
| + FetchedManifestEmpty, |
| + }; |
| + |
| + ManifestUpgradeDetector(JNIEnv* env, |
| + jobject obj, |
| + content::WebContents* web_contents, |
| + const GURL& scope, |
| + const GURL& web_manifest_url); |
| + |
| + // Replaces the WebContents that is being observed. |
| + void ReplaceWebContents( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj, |
| + const base::android::JavaParamRef<jobject>& jweb_contents); |
| + |
| + // Called by the Java counterpart to destroy its native half. |
| + void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| + |
| + // Called by the Java counterpart to start checking web manifest changes. |
| + void Start(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| + |
| + // Registers JNI hooks. |
| + static bool Register(JNIEnv* env); |
| + |
| + ErrorCode error_code() { return error_code_; } |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(ManifestUpgradeDetectorTest, |
| + OnDidGetManifestReturnsFalseWhenTheFetchedManifestUrlIsEmpty); |
| + ~ManifestUpgradeDetector() override; |
| + |
| + // content::WebContentsObserver: |
| + void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| + const GURL& validated_url) override; |
| + |
| + // Called when the Manifest has been parsed, or if no Manifest was found. |
| + void OnDidGetManifest(const GURL& manifest_url, |
| + const content::Manifest& manifest); |
| + |
| + void OnDataAvailable(const ShortcutInfo& info); |
| + |
| + // Points to the Java object. |
| + base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| + |
|
pkotwicz
2016/07/20 20:57:04
Nit: Add comments for each of the member variables
Xi Han
2016/07/22 17:13:11
Done.
|
| + bool started_; |
| + |
| + const GURL scope_; |
| + |
| + const GURL web_manifest_url_; |
| + |
| + ErrorCode error_code_; |
| + |
| + base::WeakPtrFactory<ManifestUpgradeDetector> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ManifestUpgradeDetector); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_H_ |