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_PUBLIC_PROVIDER_CHROME_BROWSER_UPDATABLE_RESOURCE_PROVIDER_H_
6 #define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_UPDATABLE_RESOURCE_PROVIDER_H_
8 #import <Foundation/Foundation.h>
10 #include "base/macros.h"
12 @protocol UpdatableResourceDelegate
;
13 @protocol UpdatableResourceDescriptorBridge
;
15 #pragma mark - UpdatableResourceBridge
17 // UpdatableResourceBridge represents an updatable resource.
18 @protocol UpdatableResourceBridge
<NSObject
>
20 // Returns the UpdatableResourceDescriptorBridge associated to this resource.
21 @
property(nonatomic
, readonly
) id
<UpdatableResourceDescriptorBridge
> descriptor
;
23 // Returns the UpdatableResourceDelegate associated to this resource.
24 - (id
<UpdatableResourceDelegate
>)delegate
;
26 // The data provided by this resource.
27 - (NSDictionary
*)resourceData
;
29 // Initializes this updatable resource with default values.
33 #pragma mark - UpdatableResourceDescriptorBridge
35 // This class encapsulates identification and versioning information
36 // for an updatable resource.
37 @protocol UpdatableResourceDescriptorBridge
<NSObject
>
39 @
property(nonatomic
, copy
) NSString
* applicationIdentifier
;
40 @
property(nonatomic
, copy
) NSString
* applicationVersion
;
42 // URL where an update to this resource may be downloaded.
43 @
property(nonatomic
, readonly
) NSURL
* updateURL
;
45 // Search path for the default file.
46 @
property(nonatomic
, copy
) NSString
* bundleResourcePath
;
47 // Search path for the downloaded file.
48 @
property(nonatomic
, copy
) NSString
* updateResourcePath
;
50 // This method must be called after an update check has been made. Either
51 // successfully or not.
52 - (void)updateCheckDidFinishWithSuccess
:(BOOL
)wasSuccessful
;
54 // Returns the full path of the latest and greatest version of the resource
55 // currently residing on the device. If there is no version of the resource
56 // currently stored on the device, returns |nil|.
57 - (NSString
*)resourcePath
;
61 #pragma mark - UpdatableResourceDelegate
63 // Delegate for UpdatableResourceBridge.
64 @protocol UpdatableResourceDelegate
<NSObject
>
66 // This method can be reimplemented to override the behavior of the
67 // UpdatableResourceBridge method.
68 - (void)loadDefaults
:(id
<UpdatableResourceBridge
>)resource
;
70 // Merges the latest values defined in the file into the values currently stored
71 // by the updatable resource.
72 - (void)mergeUpdate
:(id
<UpdatableResourceBridge
>)resource
;
74 // Parses file at |path| and returns an NSDictionary with the values stored
76 - (NSDictionary
*)parseFileAt
:(NSString
*)path
;
79 #pragma mark - UpdatableResourceProvider
83 // Provider for UpdatableResourceBridge.
84 class UpdatableResourceProvider
{
86 UpdatableResourceProvider();
87 virtual ~UpdatableResourceProvider();
89 // Returns the name of the notification that is sent through the notification
90 // center when a resource is updated.
91 virtual NSString
* GetUpdateNotificationName();
93 // Creates a new UpdatableResourceBrige.
94 // The user is responsible for releasing it.
95 // The UpdatableResourceBridge takes ownership of the delegate.
96 // |delegate| may be nil.
97 virtual id
<UpdatableResourceBridge
> CreateUpdatableResource(
98 NSString
* resource_identifier
,
99 id
<UpdatableResourceDelegate
> delegate
);
102 DISALLOW_COPY_AND_ASSIGN(UpdatableResourceProvider
);
107 #endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_UPDATABLE_RESOURCE_PROVIDER_H_