1 // Copyright 2015 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.
5 #ifndef IOS_WEB_CRW_BROWSING_DATA_STORE_H_
6 #define IOS_WEB_CRW_BROWSING_DATA_STORE_H_
8 #import <Foundation/Foundation.h>
10 #import "base/ios/block_types.h"
11 #import "ios/web/public/crw_browsing_data_store_delegate.h"
16 // Represents the various kinds of browsing data that a CRWBrowsingDataStore
18 typedef NS_OPTIONS(NSUInteger
, BrowsingDataTypes
) {
19 // Represents the cookie browsing data that a web view stores.
20 BROWSING_DATA_TYPE_COOKIES
= 1 << 0,
21 // Represents all the browsing data that a web view stores.
22 BROWSING_DATA_TYPE_ALL
= BROWSING_DATA_TYPE_COOKIES
,
25 // Represents the modes that a CRWBrowsingDataStore can be in.
26 typedef NS_ENUM(NSUInteger
, BrowsingDataStoreMode
) {
27 // Web views (associated transitively through the BrowseState) are
28 // flushing/reading their data from disk.
30 // The CRWBrowsingDataStore's mode is in the process of becoming either ACTIVE
33 // Browsing data is stored in a path unique to the BrowserState and is
34 // currently not being read or written to by web views.
40 // A CRWBrowsingDataStore represents various types of data that a web view uses.
41 // All methods must be called on the main thread.
42 @interface CRWBrowsingDataStore
: NSObject
44 // The delegate that is consulted when the mode needs to change.
45 @
property(nonatomic
, weak
) id
<CRWBrowsingDataStoreDelegate
> delegate
;
47 // The mode that the CRWBrowsingDataStore is in. KVO compliant.
48 @
property(nonatomic
, assign
, readonly
) web::BrowsingDataStoreMode mode
;
50 // A BOOL indicating whether there is still a pending operation that has not
51 // finished running. Creating web views with this CRWBrowsingDataStore when
52 // there are pending operations results in undefined behavior.
53 @
property(nonatomic
, assign
, readonly
) BOOL hasPendingOperations
;
55 // |browserState| cannot be null. The initial mode of the
56 // CRWBrowsingDataStore is obtained from the active state of the
57 // |web::ActiveStateManager| associated with |browserState|.
58 - (instancetype
)initWithBrowserState
:(web::BrowserState
*)browserState
59 NS_DESIGNATED_INITIALIZER
;
60 - (instancetype
)init NS_UNAVAILABLE
;
62 // Changes the mode to |ACTIVE|.
63 // If there is no delegate present, the default behavior of this method is to
64 // restore browsing data from |browserState|'s stash path to the canonical path
65 // where web views read/write browsing data to.
66 // |completionHandler| is called on the main thread. This block has no return
67 // value and takes a single BOOL argument that indicates whether or not the
68 // the mode was successfully changed to |ACTIVE|.
69 // The mode change to |ACTIVE| can fail if another |makeActive| or
70 // |makeInactive| was enqueued after this call.
71 // Precondition: There must be no web views associated with the BrowserState.
72 - (void)makeActiveWithCompletionHandler
:
73 (void (^)(BOOL success
))completionHandler
;
75 // Changes the mode to |INACTIVE|.
76 // If there is no delegate present, the default behavior of this method is to
77 // stash browsing data created by the web view in to the |browserState|'s stash
79 // |completionHandler| is called on the main thread. This block has no return
80 // value and takes a single BOOL argument that indicates whether or not the
81 // the mode was successfully changed to |INACTIVE|.
82 // The mode change to |INACTIVE| can fail if another |makeActive| or
83 // |makeInactive| was enqueued after this call.
84 // Precondition: There must be no web views associated with the BrowserState.
85 - (void)makeInactiveWithCompletionHandler
:
86 (void (^)(BOOL success
))completionHandler
;
88 // Removes all browsing data of the provided |browsingDataTypes|.
89 // |completionHandler| is called on the main thread after the browsing data has
91 // Precondition: There must be no web views associated with the BrowserState.
92 - (void)removeDataOfTypes
:(web::BrowsingDataTypes
)browsingDataTypes
93 completionHandler
:(ProceduralBlock
)completionHandler
;
97 #endif // IOS_WEB_CRW_BROWSING_DATA_STORE_H_