blob: 685fce55f07008b97d2b778c27f49e91de413d66 [file] [log] [blame]
[email protected]5df038b2012-07-16 19:03:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8e4560b62011-01-14 10:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5df038b2012-07-16 19:03:275#ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_
[email protected]8e4560b62011-01-14 10:09:147
dchengc963c7142016-04-08 03:55:228#include <memory>
9
[email protected]57999812013-02-24 05:40:5210#include "base/files/file_path.h"
avia2f4804a2015-12-24 23:11:1311#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]8e4560b62011-01-14 10:09:1413
[email protected]f3a1c642011-07-12 19:15:0314namespace base {
15class DictionaryValue;
16}
17
[email protected]5df038b2012-07-16 19:03:2718namespace extensions {
19class ExternalProviderImpl;
20
[email protected]8e4560b62011-01-14 10:09:1421// Base class for gathering a list of external extensions. Subclasses
22// implement loading from registry, JSON file, policy.
[email protected]5df038b2012-07-16 19:03:2723// Instances are owned by ExternalProviderImpl objects.
[email protected]8e4560b62011-01-14 10:09:1424// Instances are created on the UI thread and expect public method calls from
25// the UI thread. Some subclasses introduce new methods that are executed on the
26// FILE thread.
27// The sequence of loading the extension list:
28// 1.) StartLoading() - checks if a loading task is already running
29// 2.) Load() - implemented in subclasses
[email protected]23b00972011-10-04 17:17:2630// 3.) LoadFinished()
[email protected]8e4560b62011-01-14 10:09:1431// 4.) owner_->SetPrefs()
[email protected]5df038b2012-07-16 19:03:2732class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> {
[email protected]8e4560b62011-01-14 10:09:1433 public:
[email protected]5df038b2012-07-16 19:03:2734 ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1435
36 // Specifies the provider that owns this object.
[email protected]5df038b2012-07-16 19:03:2737 void Init(ExternalProviderImpl* owner);
[email protected]8e4560b62011-01-14 10:09:1438
39 // Called by the owner before it gets deleted.
40 void OwnerShutdown();
41
42 // Initiates the possibly asynchronous loading of extension list.
Istiaque Ahmedef99c8ea2017-09-06 21:19:5743 // Implementations of this method should call LoadFinished with results.
[email protected]8e4560b62011-01-14 10:09:1444 virtual void StartLoading() = 0;
45
[email protected]f0841cd2011-01-19 15:07:2446 // Some external providers allow relative file paths to local CRX files.
47 // Subclasses that want this behavior should override this method to
48 // return the absolute path from which relative paths should be resolved.
49 // By default, return an empty path, which indicates that relative paths
50 // are not allowed.
[email protected]650b2d52013-02-10 03:41:4551 virtual const base::FilePath GetBaseCrxFilePath();
[email protected]f0841cd2011-01-19 15:07:2452
[email protected]8e4560b62011-01-14 10:09:1453 protected:
[email protected]5df038b2012-07-16 19:03:2754 virtual ~ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1455
56 // Notifies the provider that the list of extensions has been loaded.
Istiaque Ahmedef99c8ea2017-09-06 21:19:5757 virtual void LoadFinished(std::unique_ptr<base::DictionaryValue> prefs);
[email protected]8e4560b62011-01-14 10:09:1458
lazyboye8634172016-01-28 00:10:4859 // Notifies the provider that the list of extensions has been updated.
dchengc963c7142016-04-08 03:55:2260 virtual void OnUpdated(std::unique_ptr<base::DictionaryValue> updated_prefs);
lazyboye8634172016-01-28 00:10:4861
Istiaque Ahmedef99c8ea2017-09-06 21:19:5762 // Returns true if this loader has an owner.
63 // This is useful to know if calling LoadFinished/OnUpdated will propagate
64 // prefs to our owner.
65 bool has_owner() const { return owner_ != nullptr; }
[email protected]8e4560b62011-01-14 10:09:1466
67 private:
[email protected]5df038b2012-07-16 19:03:2768 friend class base::RefCountedThreadSafe<ExternalLoader>;
[email protected]8e4560b62011-01-14 10:09:1469
[email protected]5df038b2012-07-16 19:03:2770 ExternalProviderImpl* owner_; // weak
[email protected]8e4560b62011-01-14 10:09:1471
[email protected]5df038b2012-07-16 19:03:2772 DISALLOW_COPY_AND_ASSIGN(ExternalLoader);
[email protected]8e4560b62011-01-14 10:09:1473};
74
[email protected]5df038b2012-07-16 19:03:2775} // namespace extensions
76
77#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_