1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_POLICY_APP_PACK_UPDATER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_APP_PACK_UPDATER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/chromeos/extensions/external_cache.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h"
19 namespace extensions
{
24 class URLRequestContextGetter
;
29 class AppPackExternalLoader
;
30 class EnterpriseInstallAttributes
;
32 // The AppPackUpdater manages a set of extensions that are configured via a
33 // device policy to be locally cached and installed into the Demo user account
35 class AppPackUpdater
: public chromeos::ExternalCache::Delegate
{
37 // Callback to listen for updates to the screensaver extension's path.
38 typedef base::Callback
<void(const base::FilePath
&)> ScreenSaverUpdateCallback
;
40 // The |request_context| is used for the update checks.
41 AppPackUpdater(net::URLRequestContextGetter
* request_context
,
42 EnterpriseInstallAttributes
* install_attributes
);
43 virtual ~AppPackUpdater();
45 // Returns true if the ExternalLoader for the app pack has already been
47 bool created_external_loader() const { return created_extension_loader_
; }
49 // Creates an extensions::ExternalLoader that will load the crx files
50 // downloaded by the AppPackUpdater. This can be called at most once, and the
51 // caller owns the returned value.
52 extensions::ExternalLoader
* CreateExternalLoader();
54 // |callback| will be invoked whenever the screen saver extension's path
55 // changes. It will be invoked "soon" after this call if a valid path already
56 // exists. Subsequent calls will override the previous |callback|. A null
57 // |callback| can be used to remove a previous callback.
58 void SetScreenSaverUpdateCallback(const ScreenSaverUpdateCallback
& callback
);
60 // If a user of one of the AppPack's extensions detects that the extension
61 // is damaged then this method can be used to remove it from the cache and
62 // retry to download it after a restart.
63 void OnDamagedFileDetected(const base::FilePath
& path
);
66 // Implementation of ExternalCache::Delegate:
67 virtual void OnExtensionListsUpdated(
68 const base::DictionaryValue
* prefs
) OVERRIDE
;
70 // Called when the app pack device setting changes.
71 void AppPackChanged();
73 // Loads the current policy and schedules a cache update.
76 // Notifies the |extension_loader_| that the cache has been updated, providing
77 // it with an updated list of app-pack extensions.
78 void UpdateExtensionLoader();
80 // Sets |screen_saver_path_| and invokes |screen_saver_update_callback_| if
82 void SetScreenSaverPath(const base::FilePath
& path
);
84 base::WeakPtrFactory
<AppPackUpdater
> weak_ptr_factory_
;
86 // The extension ID and path of the CRX file of the screen saver extension,
87 // if it is configured by the policy. Otherwise these fields are empty.
88 std::string screen_saver_id_
;
89 base::FilePath screen_saver_path_
;
91 // Callback to invoke whenever the screen saver's extension path changes.
93 ScreenSaverUpdateCallback screen_saver_update_callback_
;
95 // The extension loader wires the AppPackUpdater to the extensions system, and
96 // makes it install the currently cached extensions.
97 bool created_extension_loader_
;
98 base::WeakPtr
<AppPackExternalLoader
> extension_loader_
;
100 // For checking the device mode.
101 EnterpriseInstallAttributes
* install_attributes_
;
104 chromeos::ExternalCache external_cache_
;
106 scoped_ptr
<chromeos::CrosSettings::ObserverSubscription
>
107 app_pack_subscription_
;
109 DISALLOW_COPY_AND_ASSIGN(AppPackUpdater
);
112 } // namespace policy
114 #endif // CHROME_BROWSER_CHROMEOS_POLICY_APP_PACK_UPDATER_H_