blob: 121583624d8df8f5562d5c6783846b4083df640c [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"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
[email protected]8e4560b62011-01-14 10:09:1411
[email protected]f3a1c642011-07-12 19:15:0312namespace base {
13class DictionaryValue;
14}
15
[email protected]5df038b2012-07-16 19:03:2716namespace extensions {
17class ExternalProviderImpl;
18
[email protected]8e4560b62011-01-14 10:09:1419// Base class for gathering a list of external extensions. Subclasses
20// implement loading from registry, JSON file, policy.
[email protected]5df038b2012-07-16 19:03:2721// Instances are owned by ExternalProviderImpl objects.
[email protected]8e4560b62011-01-14 10:09:1422// 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
[email protected]23b00972011-10-04 17:17:2628// 3.) LoadFinished()
[email protected]8e4560b62011-01-14 10:09:1429// 4.) owner_->SetPrefs()
[email protected]5df038b2012-07-16 19:03:2730class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> {
[email protected]8e4560b62011-01-14 10:09:1431 public:
[email protected]5df038b2012-07-16 19:03:2732 ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1433
34 // Specifies the provider that owns this object.
[email protected]5df038b2012-07-16 19:03:2735 void Init(ExternalProviderImpl* owner);
[email protected]8e4560b62011-01-14 10:09:1436
37 // Called by the owner before it gets deleted.
38 void OwnerShutdown();
39
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;
46
[email protected]f0841cd2011-01-19 15:07:2447 // 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.
[email protected]650b2d52013-02-10 03:41:4552 virtual const base::FilePath GetBaseCrxFilePath();
[email protected]f0841cd2011-01-19 15:07:2453
[email protected]8e4560b62011-01-14 10:09:1454 protected:
[email protected]5df038b2012-07-16 19:03:2755 virtual ~ExternalLoader();
[email protected]8e4560b62011-01-14 10:09:1456
57 // Notifies the provider that the list of extensions has been loaded.
58 void LoadFinished();
59
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.
[email protected]f3a1c642011-07-12 19:15:0367 scoped_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:1468
69 private:
[email protected]5df038b2012-07-16 19:03:2770 friend class base::RefCountedThreadSafe<ExternalLoader>;
[email protected]8e4560b62011-01-14 10:09:1471
[email protected]5df038b2012-07-16 19:03:2772 ExternalProviderImpl* owner_; // weak
[email protected]8e4560b62011-01-14 10:09:1473
74 // Set to true if loading the extensions is already running. New requests
75 // are ignored while this is set true.
76 bool running_;
77
[email protected]5df038b2012-07-16 19:03:2778 DISALLOW_COPY_AND_ASSIGN(ExternalLoader);
[email protected]8e4560b62011-01-14 10:09:1479};
80
[email protected]5df038b2012-07-16 19:03:2781} // namespace extensions
82
83#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_