summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshreyasv <shreyasv@chromium.org>2015-06-01 18:13:14 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-02 01:13:48 +0000
commitf9b662a5e84c707274b2fb58f25b3740b21004cd (patch)
tree6fbc9f3eba4ed30b8a4db73d9b4eac4b8a932bbc
parentca9ccb8fa2f7659879374b612b20a93c42608539 (diff)
downloadchromium_src-f9b662a5e84c707274b2fb58f25b3740b21004cd.zip
chromium_src-f9b662a5e84c707274b2fb58f25b3740b21004cd.tar.gz
chromium_src-f9b662a5e84c707274b2fb58f25b3740b21004cd.tar.bz2
Added a CRWBrowsingDataStoreDelegate
This delegate is consulted whenever a CRWBrowsingDataStore's mode wants to become |ACTIVE| or |INACTIVE|. The default behavior of stashing and restoring browsing data does not fit all use cases and this decision needs to be delegated over. Added a TODO to actually consult the delegate when a mode change occurs. BUG=480654 Review URL: https://codereview.chromium.org/1151063004 Cr-Commit-Position: refs/heads/master@{#332293}
-rw-r--r--ios/web/crw_browsing_data_store.mm16
-rw-r--r--ios/web/ios_web.gyp1
-rw-r--r--ios/web/public/crw_browsing_data_store.h11
-rw-r--r--ios/web/public/crw_browsing_data_store_delegate.h53
4 files changed, 81 insertions, 0 deletions
diff --git a/ios/web/crw_browsing_data_store.mm b/ios/web/crw_browsing_data_store.mm
index 646bb5a..4f36a22 100644
--- a/ios/web/crw_browsing_data_store.mm
+++ b/ios/web/crw_browsing_data_store.mm
@@ -84,6 +84,8 @@ enum OperationType {
@implementation CRWBrowsingDataStore {
web::BrowserState* _browserState; // Weak, owns this object.
+ // The delegate.
+ base::WeakNSProtocol<id<CRWBrowsingDataStoreDelegate>> _delegate;
// The mode of the CRWBrowsingDataStore.
CRWBrowsingDataStoreMode _mode;
// The dictionary that maps a browsing data type to its
@@ -180,6 +182,14 @@ enum OperationType {
return result;
}
+- (id<CRWBrowsingDataStoreDelegate>)delegate {
+ return _delegate;
+}
+
+- (void)setDelegate:(id<CRWBrowsingDataStoreDelegate>)delegate {
+ _delegate.reset(delegate);
+}
+
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString*)key {
// It is necessary to override this for |mode| because the default KVO
// behavior in NSObject is to fire a notification irrespective of if an actual
@@ -241,6 +251,9 @@ enum OperationType {
(void (^)(BOOL success))completionHandler {
DCHECK([NSThread isMainThread]);
+ // TODO(shreyasv): Consult the delegate here if it wants to |DELETE| instead.
+ // crbug.com/480654.
+
base::WeakNSObject<CRWBrowsingDataStore> weakSelf(self);
[self performOperationWithType:RESTORE
browsingDataManagers:[self allBrowsingDataManagers]
@@ -254,6 +267,9 @@ enum OperationType {
(void (^)(BOOL success))completionHandler {
DCHECK([NSThread isMainThread]);
+ // TODO(shreyasv): Consult the delegate here if it wants to |DELETE| instead.
+ // crbug.com/480654.
+
base::WeakNSObject<CRWBrowsingDataStore> weakSelf(self);
[self performOperationWithType:STASH
browsingDataManagers:[self allBrowsingDataManagers]
diff --git a/ios/web/ios_web.gyp b/ios/web/ios_web.gyp
index 146592d..da17880 100644
--- a/ios/web/ios_web.gyp
+++ b/ios/web/ios_web.gyp
@@ -143,6 +143,7 @@
'public/browser_url_rewriter.h',
'public/browsing_data_partition.h',
'public/crw_browsing_data_store.h',
+ 'public/crw_browsing_data_store_delegate.h',
'public/cert_policy.h',
'public/cert_store.h',
'public/certificate_policy_cache.h',
diff --git a/ios/web/public/crw_browsing_data_store.h b/ios/web/public/crw_browsing_data_store.h
index c23f388..e957b65 100644
--- a/ios/web/public/crw_browsing_data_store.h
+++ b/ios/web/public/crw_browsing_data_store.h
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import "base/ios/block_types.h"
+#import "ios/web/public/crw_browsing_data_store_delegate.h"
namespace web {
class BrowserState;
@@ -47,6 +48,9 @@ enum CRWBrowsingDataStoreMode {
- (instancetype)initWithBrowserState:(web::BrowserState*)browserState
NS_DESIGNATED_INITIALIZER;
+// The delegate that is consulted when the mode needs to change.
+@property(nonatomic, weak) id<CRWBrowsingDataStoreDelegate> delegate;
+
// The mode that the CRWBrowsingDataStore is in. KVO compliant.
@property(nonatomic, assign, readonly) CRWBrowsingDataStoreMode mode;
@@ -54,6 +58,9 @@ enum CRWBrowsingDataStoreMode {
// web::WebViewCounter class is implemented. crbug.com/480507
// Changes the mode to |ACTIVE|.
+// if there is no delegate present, the default behavior of this method is to
+// restore browsing data from |browserState|'s stash path to the canonical path
+// where web views read/write browsing data to.
// |completionHandler| is called on the main thread. This block has no return
// value and takes a single BOOL argument that indicates whether or not the
// the mode was successfully changed to |ACTIVE|.
@@ -64,6 +71,10 @@ enum CRWBrowsingDataStoreMode {
(void (^)(BOOL success))completionHandler;
// Changes the mode to |INACTIVE|.
+// if there is no delegate present, the default behavior of this method is to
+// value and takes a single BOOL argument that indicates whether or not the
+// stash browsing data created by the web view in to |browserState|'s stash
+// path.
// |completionHandler| is called on the main thread. This block has no return
// value and takes a single BOOL argument that indicates whether or not the
// the mode was successfully changed to |INACTIVE|.
diff --git a/ios/web/public/crw_browsing_data_store_delegate.h b/ios/web/public/crw_browsing_data_store_delegate.h
new file mode 100644
index 0000000..22b2352
--- /dev/null
+++ b/ios/web/public/crw_browsing_data_store_delegate.h
@@ -0,0 +1,53 @@
+// Copyright 2015 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 IOS_WEB_CRW_BROWSING_DATA_STORE_DELEGATE_H_
+#define IOS_WEB_CRW_BROWSING_DATA_STORE_DELEGATE_H_
+
+#import <Foundation/Foundation.h>
+
+@class CRWBrowsingDataStore;
+
+namespace web {
+
+// The policy to pass back to the CRWBrowsingDataStore when the
+// CRWBrowsingDataStore's mode wants to become |ACTIVE|.
+typedef NS_ENUM(NSUInteger, BrowsingDataStoreMakeActivePolicy) {
+ // Adopt browsing data to the canonical path where web views store their
+ // browsing data.
+ ADOPT = 1,
+ // Restore browsing data from the stash path. This is the default policy and
+ // is the same policy that is used if the delegate was not implemented.
+ RESTORE,
+};
+
+// The policy to pass back to the CRWBrowsingDataStore when the
+// CRWBrowsingDataStore's mode wants to become |INACTIVE|.
+typedef NS_ENUM(NSUInteger, BrowsingDataStoreMakeInactivePolicy) {
+ // Delete browsing data created by the web views.
+ DELETE = 1,
+ // Stash browsing data created by the web views. This is the default policy
+ // and is the same policy that is used if the delegate was not implemented.
+ STASH,
+};
+
+} // namespace web
+
+// The CRWBrowsingDataStoreDelegate has methods that can override the default
+// behavior of a CRWBrowsingDataStoreMode when a mode change occurs.
+@protocol CRWBrowsingDataStoreDelegate<NSObject>
+
+// Called when a CRWBrowsingDataStore wants to change its mode to |ACTIVE|.
+- (web::BrowsingDataStoreMakeActivePolicy)
+ decideMakeActiveOperationPolicyForBrowsingDataStore:
+ (CRWBrowsingDataStore*)browsingDataStore;
+
+// Called when a CRWBrowsingDataStore wants to change its mode to |INACTIVE|.
+- (web::BrowsingDataStoreMakeActivePolicy)
+ decideMakeInactiveOperationPolicyForBrowsingDataStore:
+ (CRWBrowsingDataStore*)browsingDataStore;
+
+@end
+
+#endif // IOS_WEB_CRW_BROWSING_DATA_STORE_DELEGATE_H_