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

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

Issue 9595001: Apps on NTP should be in order of installation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <list>
10 #include <string> 10 #include <string>
11 #include <utility>
11 12
12 #include "chrome/browser/extensions/pending_extension_info.h" 13 #include "chrome/browser/extensions/pending_extension_info.h"
13 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
14 15
15 class ExtensionServiceInterface; 16 class ExtensionServiceInterface;
16 class GURL; 17 class GURL;
17 18
18 // Class PendingExtensionManager manages the set of extensions which are 19 // Class PendingExtensionManager manages the set of extensions which are
19 // being installed or updated. In general, installation and updates take 20 // being installed or updated. In general, installation and updates take
20 // time, because they involve downloading, unpacking, and installing. 21 // time, because they involve downloading, unpacking, and installing.
21 // This class allows us to avoid race cases where multiple sources install 22 // This class allows us to avoid race cases where multiple sources install
22 // the same extension. 23 // the same extension.
23 // The extensions service creates an instance of this class, and manages 24 // The extensions service creates an instance of this class, and manages
24 // its lifetime. This class should only be used from the UI thread. 25 // its lifetime. This class should only be used from the UI thread.
25 class PendingExtensionManager { 26 class PendingExtensionManager {
26 public: 27 public:
27 // |service| is a reference to the ExtensionService whose pending 28 // |service| is a reference to the ExtensionService whose pending
28 // extensions we are managing. The service creates an instance of 29 // extensions we are managing. The service creates an instance of
29 // this class on construction, and destroys it on destruction. 30 // this class on construction, and destroys it on destruction.
30 // The service remains valid over the entire lifetime of this class. 31 // The service remains valid over the entire lifetime of this class.
31 explicit PendingExtensionManager(const ExtensionServiceInterface& service); 32 explicit PendingExtensionManager(const ExtensionServiceInterface& service);
32 ~PendingExtensionManager(); 33 ~PendingExtensionManager();
33 34
34 // TODO(skerner): Many of these methods can be private once code in 35 // TODO(skerner): Many of these methods can be private once code in
35 // ExtensionService is moved into methods of this class. 36 // ExtensionService is moved into methods of this class.
36 37
37 // Remove |id| from the set of pending extensions. 38 // Remove |id| from the set of pending extensions.
38 void Remove(const std::string& id); 39 bool Remove(const std::string& id);
39 40
40 // Get the information for a pending extension. Returns true and sets 41 // Get the information for a pending extension. Returns true and sets
41 // |out_pending_extension_info| if there is a pending extension with id 42 // |out_pending_extension_info| if there is a pending extension with id
42 // |id|. Returns false otherwise. 43 // |id|. Returns false otherwise.
43 bool GetById(const std::string& id, 44 bool GetById(const std::string& id,
44 PendingExtensionInfo* out_pending_extension_info) const; 45 PendingExtensionInfo* out_pending_extension_info) const;
45 46
46 // Is |id| in the set of pending extensions? 47 // Is |id| in the set of pending extensions?
47 bool IsIdPending(const std::string& id) const; 48 bool IsIdPending(const std::string& id) const;
48 49
(...skipping 18 matching lines...) Expand all
67 const GURL& update_url, 68 const GURL& update_url,
68 Extension::Location location); 69 Extension::Location location);
69 70
70 // Add a pending extension record for an external CRX file. 71 // Add a pending extension record for an external CRX file.
71 // Return true if the CRX should be installed, false if an existing 72 // Return true if the CRX should be installed, false if an existing
72 // pending record overrides it. 73 // pending record overrides it.
73 bool AddFromExternalFile( 74 bool AddFromExternalFile(
74 const std::string& id, 75 const std::string& id,
75 Extension::Location location); 76 Extension::Location location);
76 77
77 // Get the set of pending IDs that should be installed from an update URL. 78 // Get the list of pending IDs that should be installed from an update URL.
78 // Pending extensions that will be installed from local files will not be 79 // Pending extensions that will be installed from local files will not be
79 // included in the set. 80 // included in the set.
80 void GetPendingIdsForUpdateCheck( 81 void GetPendingIdsForUpdateCheck(
81 std::set<std::string>* out_ids_for_update_check) const; 82 std::list<std::string>* out_ids_for_update_check) const;
82 83
83 private: 84 private:
84 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; 85 typedef std::list<std::pair<std::string,
86 PendingExtensionInfo> > PendingExtensionList;
85 87
86 // Assumes an extension with id |id| is not already installed. 88 // Assumes an extension with id |id| is not already installed.
87 // Return true if the extension was added. 89 // Return true if the extension was added.
88 bool AddExtensionImpl( 90 bool AddExtensionImpl(
89 const std::string& id, 91 const std::string& id,
90 const GURL& update_url, 92 const GURL& update_url,
91 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, 93 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
92 bool is_from_sync, 94 bool is_from_sync,
93 bool install_silently, 95 bool install_silently,
94 Extension::Location install_source); 96 Extension::Location install_source);
95 97
96 // Add a pending extension record directly. Used for unit tests that need 98 // Add a pending extension record directly. Used for unit tests that need
97 // to set an inital state. Use friendship to allow the tests to call this 99 // to set an inital state. Use friendship to allow the tests to call this
98 // method. 100 // method.
99 void AddForTesting(const std::string& id, 101 void AddForTesting(const std::string& id,
100 const PendingExtensionInfo& pending_etension_info); 102 const PendingExtensionInfo& pending_etension_info);
101 103
104 // Returns an iter pointing at a pair in PendingExtensionList, so iteration
105 // code need not be repeated
106 PendingExtensionList::iterator GetExtensionListIterById(
107 const std::string& id);
108
109 PendingExtensionList::const_iterator GetExtensionListConstIterById(
110 const std::string& id) const;
111
102 // Reference to the extension service whose pending extensions this class is 112 // Reference to the extension service whose pending extensions this class is
103 // managing. Because this class is a member of |service_|, it is created 113 // managing. Because this class is a member of |service_|, it is created
104 // and destroyed with |service_|. We only use methods from the interface 114 // and destroyed with |service_|. We only use methods from the interface
105 // ExtensionServiceInterface. 115 // ExtensionServiceInterface.
106 const ExtensionServiceInterface& service_; 116 const ExtensionServiceInterface& service_;
107 117
108 // A map from extension id to the pending extension info for that extension. 118 // A list of pairs of <extension id, pending extension info>
109 PendingExtensionMap pending_extension_map_; 119 PendingExtensionList pending_extension_list_;
110 120
111 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 121 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
112 UpdatePendingExtensionAlreadyInstalled); 122 UpdatePendingExtensionAlreadyInstalled);
113 friend class ExtensionUpdaterTest; 123 friend class ExtensionUpdaterTest;
114 friend void SetupPendingExtensionManagerForTest( 124 friend void SetupPendingExtensionManagerForTest(
115 int count, const GURL& update_url, 125 int count, const GURL& update_url,
116 PendingExtensionManager* pending_extension_manager); 126 PendingExtensionManager* pending_extension_manager);
117 127
118 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); 128 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
119 }; 129 };
120 130
121 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ 131 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
132
Aaron Boodman 2012/04/05 22:06:43 extra line
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698