From a9523b3e01e810b23be016a4ab1b45c008ddc805 Mon Sep 17 00:00:00 2001 From: shreyasv Date: Mon, 1 Jun 2015 18:42:04 -0700 Subject: [PATCH] Adding an IsSynchronized method to BrowsingDataPartition. This reflects the fact that an ActiveStateManager's active state is out of sync with its CRWBrowsingDataStore's mode. WKWebViews can only be created when the BrowsingDataPartition is fully synchronized. Added a DCHECK in the web view creation util methods that vend a WKWebView along with an appropriate comment in the .h BUG=480654 Review URL: https://codereview.chromium.org/1153143006 Cr-Commit-Position: refs/heads/master@{#332314} --- ios/web/browsing_data_partition_impl.mm | 8 ++++++++ ios/web/public/browsing_data_partition.h | 11 +++++++++++ ios/web/web_state/web_view_creation_utils.h | 4 ++++ ios/web/web_state/web_view_creation_utils.mm | 9 +++++++++ 4 files changed, 32 insertions(+) diff --git a/ios/web/browsing_data_partition_impl.mm b/ios/web/browsing_data_partition_impl.mm index 377a8c90911d..f5ebf0e1e659 100644 --- a/ios/web/browsing_data_partition_impl.mm +++ b/ios/web/browsing_data_partition_impl.mm @@ -29,6 +29,14 @@ BrowsingDataPartitionImpl::~BrowsingDataPartitionImpl() { } } +// static +bool BrowsingDataPartition::IsSynchronized() { + // TODO(shreyasv): Implement the logic to track the count of + // CRWBrowsingDataManagers whose mode is out of sync with their associated + // ActiveStateManager. Return true for now. crbug.com/480654. + return true; +} + CRWBrowsingDataStore* BrowsingDataPartitionImpl::GetBrowsingDataStore() { DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI); diff --git a/ios/web/public/browsing_data_partition.h b/ios/web/public/browsing_data_partition.h index 26ca9702cc8f..e7af73604b1d 100644 --- a/ios/web/public/browsing_data_partition.h +++ b/ios/web/public/browsing_data_partition.h @@ -21,6 +21,17 @@ class BrowserState; // Not thread safe. Must be used only on the main thread. class BrowsingDataPartition { public: + // Returns true if the BrowsingDataParition is synchronized. + // There is a moment of time when an ActiveStateManager's active state is out + // of sync with its associated CRWBrowsingDataStore's mode, this method's + // return value reflects that. + // If the BrowsingDataPartition is synchronized, every CRWBrowsingDataStore's + // mode matches its associated ActiveStateManager's active state. + // If BrowsingDataPartition is not synchronized, this means that a + // CRWBrowsingDataStore's mode is in the process of changing to its associated + // ActiveStateManager's active state. + static bool IsSynchronized(); + // Returns the underlying CRWBrowsingDataStore. virtual CRWBrowsingDataStore* GetBrowsingDataStore() = 0; diff --git a/ios/web/web_state/web_view_creation_utils.h b/ios/web/web_state/web_view_creation_utils.h index 6bab9d1aed82..e4be6d9eae88 100644 --- a/ios/web/web_state/web_view_creation_utils.h +++ b/ios/web/web_state/web_view_creation_utils.h @@ -35,6 +35,7 @@ UIWebView* CreateWebView(CGRect frame); // user agent string that includes the |request_group_id|. // |browser_state| cannot be null. The |configuration| should have the same // WKProcessPool as the WKWebViewConfiguration associated with |browser_state|. +// The BrowsingDataPartition must be synchronized before this method is called. // Note: Callers are responsible for releasing the returned WKWebView. WKWebView* CreateWKWebView(CGRect frame, WKWebViewConfiguration* configuration, @@ -45,6 +46,7 @@ WKWebView* CreateWKWebView(CGRect frame, // Returns a new WKWebView for displaying regular web content. // WKWebViewConfiguration object for resulting web view will be obtained from // the given |browser_state| which must not be null. +// The BrowsingDataPartition must be synchronized before this method is called. // Note: Callers are responsible for releasing the returned WKWebView. WKWebView* CreateWKWebView(CGRect frame, BrowserState* browser_state); @@ -54,6 +56,7 @@ WKWebView* CreateWKWebView(CGRect frame, BrowserState* browser_state); NSUInteger GetActiveWKWebViewsCount(); // Returns a CRWSimpleWebViewController for managing/showing a web view. +// The BrowsingDataPartition must be synchronized before this method is called. // Note: Callers are responsible for releasing the CRWSimpleWebViewController. id CreateSimpleWebViewController( CGRect frame, @@ -62,6 +65,7 @@ id CreateSimpleWebViewController( // Returns a new CRWSimpleWebViewController subclass displaying static HTML file // content stored in the application bundle. +// The BrowsingDataPartition must be synchronized before this method is called. // Note: Callers are responsible for releasing the returned ViewController. id CreateStaticFileSimpleWebViewController( CGRect frame, diff --git a/ios/web/web_state/web_view_creation_utils.mm b/ios/web/web_state/web_view_creation_utils.mm index 68f65701128a..ff5c9264dd64 100644 --- a/ios/web/web_state/web_view_creation_utils.mm +++ b/ios/web/web_state/web_view_creation_utils.mm @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/mac/scoped_nsobject.h" #import "ios/web/alloc_with_zone_interceptor.h" +#import "ios/web/public/browsing_data_partition.h" #include "ios/web/public/browser_state.h" #include "ios/web/public/web_client.h" #include "ios/web/ui_web_view_util.h" @@ -130,6 +131,8 @@ WKWebView* CreateWKWebView(CGRect frame, NSString* request_group_id, BOOL use_desktop_user_agent) { DCHECK(browser_state); + DCHECK(web::BrowsingDataPartition::IsSynchronized()); + WKWebViewConfigurationProvider& config_provider = WKWebViewConfigurationProvider::FromBrowserState(browser_state); DCHECK_EQ([config_provider.GetWebViewConfiguration() processPool], @@ -141,6 +144,8 @@ WKWebView* CreateWKWebView(CGRect frame, WKWebView* CreateWKWebView(CGRect frame, BrowserState* browser_state) { DCHECK(browser_state); + DCHECK(web::BrowsingDataPartition::IsSynchronized()); + WKWebViewConfigurationProvider& config_provider = WKWebViewConfigurationProvider::FromBrowserState(browser_state); return CreateWKWebViewWithConfiguration( @@ -161,6 +166,8 @@ id CreateSimpleWebViewController( CGRect frame, BrowserState* browser_state, WebViewType web_view_type) { + DCHECK(web::BrowsingDataPartition::IsSynchronized()); + // Transparently return the correct subclass. if (web_view_type == WK_WEB_VIEW_TYPE) { base::scoped_nsobject web_view( @@ -175,6 +182,8 @@ id CreateStaticFileSimpleWebViewController( CGRect frame, BrowserState* browser_state, WebViewType web_view_type) { + DCHECK(web::BrowsingDataPartition::IsSynchronized()); + // Transparently return the correct subclass. if (web_view_type == WK_WEB_VIEW_TYPE) { // TOOD(shreyasv): Create a new util function vending a WKWebView, wrap that -- 2.11.4.GIT