blob: 50c06ba17b2836e09b2541d99fdfc703c2865d5c [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
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
avia2f4804a2015-12-24 23:11:139#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
11#include "base/memory/scoped_ptr.h"
[email protected]8e4560b62011-01-14 10:09:1412
[email protected]f3a1c642011-07-12 19:15:0313namespace base {
14class DictionaryValue;
15}
16
[email protected]5df038b2012-07-16 19:03:2717namespace extensions {
18class ExternalProviderImpl;
19
[email protected]8e4560b62011-01-14 10:09:1420// Base class for gathering a list of external extensions. Subclasses
21// implement loading from registry, JSON file, policy.
[email protected]5df038b2012-07-16 19:03:2722// Instances are owned by ExternalProviderImpl objects.
[email protected]8e4560b62011-01-14 10:09:1423// Instances are created on the UI thread and expect public method calls from
24// the UI thread. Some subclasses introduce new methods that are executed on the
25// FILE thread.
26// The sequence of loading the extension list:
27// 1.) StartLoading() - checks if a loading task is already running
28// 2.) Load() - implemented in subclasses
[email protected]23b00972011-10-04 17:17:2629// 3.) LoadFinished()
[email protected]8e4560b62011-01-14 10:09:1430// 4.) owner_->SetPrefs()
[email protected]5df038b2012-07-16 19:03:2731class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> {
[email protected]8e4560b62011-01-14 10:09:1432 public:
[email protected]5df038b2012-07-16 19:03:2733 ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1434
35 // Specifies the provider that owns this object.
[email protected]5df038b2012-07-16 19:03:2736 void Init(ExternalProviderImpl* owner);
[email protected]8e4560b62011-01-14 10:09:1437
38 // Called by the owner before it gets deleted.
39 void OwnerShutdown();
40
41 // Initiates the possibly asynchronous loading of extension list.
42 // It is the responsibility of the caller to ensure that calls to
43 // this method do not overlap with each other.
44 // Implementations of this method should save the loaded results
45 // in prefs_ and then call LoadFinished.
46 virtual void StartLoading() = 0;
47
[email protected]f0841cd2011-01-19 15:07:2448 // Some external providers allow relative file paths to local CRX files.
49 // Subclasses that want this behavior should override this method to
50 // return the absolute path from which relative paths should be resolved.
51 // By default, return an empty path, which indicates that relative paths
52 // are not allowed.
[email protected]650b2d52013-02-10 03:41:4553 virtual const base::FilePath GetBaseCrxFilePath();
[email protected]f0841cd2011-01-19 15:07:2454
[email protected]8e4560b62011-01-14 10:09:1455 protected:
[email protected]5df038b2012-07-16 19:03:2756 virtual ~ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1457
58 // Notifies the provider that the list of extensions has been loaded.
[email protected]a4567732013-07-25 21:01:2059 virtual void LoadFinished();
[email protected]8e4560b62011-01-14 10:09:1460
61 // Used for passing the list of extensions from the method that loads them
62 // to |LoadFinished|. To ensure thread safety, the rules are the following:
63 // if this value is written on another thread than the UI, then it should
64 // only be written in a task that was posted from |StartLoading|. After that,
65 // this task should invoke |LoadFinished| with a PostTask. This scheme of
66 // posting tasks will avoid concurrent access and imply the necessary memory
67 // barriers.
[email protected]f3a1c642011-07-12 19:15:0368 scoped_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:1469
70 private:
[email protected]5df038b2012-07-16 19:03:2771 friend class base::RefCountedThreadSafe<ExternalLoader>;
[email protected]8e4560b62011-01-14 10:09:1472
[email protected]5df038b2012-07-16 19:03:2773 ExternalProviderImpl* owner_; // weak
[email protected]8e4560b62011-01-14 10:09:1474
[email protected]5df038b2012-07-16 19:03:2775 DISALLOW_COPY_AND_ASSIGN(ExternalLoader);
[email protected]8e4560b62011-01-14 10:09:1476};
77
[email protected]5df038b2012-07-16 19:03:2778} // namespace extensions
79
80#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_