base::Time multiplicative operator overloading
[chromium-blink-merge.git] / chrome / browser / extensions / external_loader.h
blobecadda0cb7f920473f7e4eff69aa5686fa7fc966
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_EXTENSIONS_EXTERNAL_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
12 namespace base {
13 class DictionaryValue;
16 namespace extensions {
17 class ExternalProviderImpl;
19 // Base class for gathering a list of external extensions. Subclasses
20 // implement loading from registry, JSON file, policy.
21 // Instances are owned by ExternalProviderImpl objects.
22 // Instances are created on the UI thread and expect public method calls from
23 // the UI thread. Some subclasses introduce new methods that are executed on the
24 // FILE thread.
25 // The sequence of loading the extension list:
26 // 1.) StartLoading() - checks if a loading task is already running
27 // 2.) Load() - implemented in subclasses
28 // 3.) LoadFinished()
29 // 4.) owner_->SetPrefs()
30 class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> {
31 public:
32 ExternalLoader();
34 // Specifies the provider that owns this object.
35 void Init(ExternalProviderImpl* owner);
37 // Called by the owner before it gets deleted.
38 void OwnerShutdown();
40 // Initiates the possibly asynchronous loading of extension list.
41 // It is the responsibility of the caller to ensure that calls to
42 // this method do not overlap with each other.
43 // Implementations of this method should save the loaded results
44 // in prefs_ and then call LoadFinished.
45 virtual void StartLoading() = 0;
47 // Some external providers allow relative file paths to local CRX files.
48 // Subclasses that want this behavior should override this method to
49 // return the absolute path from which relative paths should be resolved.
50 // By default, return an empty path, which indicates that relative paths
51 // are not allowed.
52 virtual const base::FilePath GetBaseCrxFilePath();
54 protected:
55 virtual ~ExternalLoader();
57 // Notifies the provider that the list of extensions has been loaded.
58 virtual void LoadFinished();
60 // Used for passing the list of extensions from the method that loads them
61 // to |LoadFinished|. To ensure thread safety, the rules are the following:
62 // if this value is written on another thread than the UI, then it should
63 // only be written in a task that was posted from |StartLoading|. After that,
64 // this task should invoke |LoadFinished| with a PostTask. This scheme of
65 // posting tasks will avoid concurrent access and imply the necessary memory
66 // barriers.
67 scoped_ptr<base::DictionaryValue> prefs_;
69 private:
70 friend class base::RefCountedThreadSafe<ExternalLoader>;
72 ExternalProviderImpl* owner_; // weak
74 DISALLOW_COPY_AND_ASSIGN(ExternalLoader);
77 } // namespace extensions
79 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_