Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chrome/browser/extensions/external_extension_loader.h

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_
7 #pragma once
8
9 #include "base/ref_counted.h"
10 #include "base/scoped_ptr.h"
11
12 class DictionaryValue;
13 class ExternalExtensionProviderImpl;
14
15 // Base class for gathering a list of external extensions. Subclasses
16 // implement loading from registry, JSON file, policy.
17 // Instances are owned by ExternalExtensionProviderImpl objects.
18 // Instances are created on the UI thread and expect public method calls from
19 // the UI thread. Some subclasses introduce new methods that are executed on the
20 // FILE thread.
21 // The sequence of loading the extension list:
22 // 1.) StartLoading() - checks if a loading task is already running
23 // 2.) Load() - implemented in subclasses
24 // 3.) FinishLoading()
25 // 4.) owner_->SetPrefs()
26 class ExternalExtensionLoader
27 : public base::RefCountedThreadSafe<ExternalExtensionLoader> {
28 public:
29 explicit ExternalExtensionLoader() : running_(false) {}
30
31 // Specifies the provider that owns this object.
32 void Init(ExternalExtensionProviderImpl* owner);
33
34 // Called by the owner before it gets deleted.
35 void OwnerShutdown();
36
37 // Initiates the possibly asynchronous loading of extension list.
38 // It is the responsibility of the caller to ensure that calls to
39 // this method do not overlap with each other.
40 // Implementations of this method should save the loaded results
41 // in prefs_ and then call LoadFinished.
42 virtual void StartLoading() = 0;
43
44 protected:
45 virtual ~ExternalExtensionLoader() {}
46
47 // Notifies the provider that the list of extensions has been loaded.
48 void LoadFinished();
49
50 // Used for passing the list of extensions from the method that loads them
51 // to |LoadFinished|. To ensure thread safety, the rules are the following:
52 // if this value is written on another thread than the UI, then it should
53 // only be written in a task that was posted from |StartLoading|. After that,
54 // this task should invoke |LoadFinished| with a PostTask. This scheme of
55 // posting tasks will avoid concurrent access and imply the necessary memory
56 // barriers.
57 scoped_ptr<DictionaryValue> prefs_;
58
59 private:
60 friend class base::RefCountedThreadSafe<ExternalExtensionLoader>;
61
62 ExternalExtensionProviderImpl* owner_; // weak
63
64 // Set to true if loading the extensions is already running. New requests
65 // are ignored while this is set true.
66 bool running_;
67
68 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionLoader);
69 };
70
71 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | chrome/browser/extensions/external_extension_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698