OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSION_PREFS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/extensions/extension_content_settings_store.h" | 15 #include "chrome/browser/extensions/extension_content_settings_store.h" |
16 #include "chrome/browser/extensions/extension_prefs_scope.h" | 16 #include "chrome/browser/extensions/extension_prefs_scope.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/string_ordinal.h" | |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 | 21 |
21 class ExtensionPrefValueMap; | 22 class ExtensionPrefValueMap; |
22 class URLPatternSet; | 23 class URLPatternSet; |
23 | 24 |
24 // Class for managing global and per-extension preferences. | 25 // Class for managing global and per-extension preferences. |
25 // | 26 // |
26 // This class distinguishes the following kinds of preferences: | 27 // This class distinguishes the following kinds of preferences: |
27 // - global preferences: | 28 // - global preferences: |
28 // internal state for the extension system in general, not associated | 29 // internal state for the extension system in general, not associated |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // ExtensionService::IsExtensionEnabled instead. | 93 // ExtensionService::IsExtensionEnabled instead. |
93 bool IsExtensionDisabled(const std::string& id) const; | 94 bool IsExtensionDisabled(const std::string& id) const; |
94 | 95 |
95 // Get the order that the browser actions appear in the toolbar. | 96 // Get the order that the browser actions appear in the toolbar. |
96 std::vector<std::string> GetToolbarOrder(); | 97 std::vector<std::string> GetToolbarOrder(); |
97 | 98 |
98 // Set the order that the browser actions appear in the toolbar. | 99 // Set the order that the browser actions appear in the toolbar. |
99 void SetToolbarOrder(const std::vector<std::string>& extension_ids); | 100 void SetToolbarOrder(const std::vector<std::string>& extension_ids); |
100 | 101 |
101 // Called when an extension is installed, so that prefs get created. | 102 // Called when an extension is installed, so that prefs get created. |
102 // If |page_index| is -1, and the then a page will be found for the App. | 103 // If |page_index| is kUnsetIndex, and the then a page will be found |
104 // for the App. | |
103 void OnExtensionInstalled(const Extension* extension, | 105 void OnExtensionInstalled(const Extension* extension, |
104 Extension::State initial_state, | 106 Extension::State initial_state, |
105 bool from_webstore, | 107 bool from_webstore, |
106 int page_index); | 108 StringOrdinal page_index); |
107 | 109 |
108 // Called when an extension is uninstalled, so that prefs get cleaned up. | 110 // Called when an extension is uninstalled, so that prefs get cleaned up. |
109 void OnExtensionUninstalled(const std::string& extension_id, | 111 void OnExtensionUninstalled(const std::string& extension_id, |
110 const Extension::Location& location, | 112 const Extension::Location& location, |
111 bool external_uninstall); | 113 bool external_uninstall); |
112 | 114 |
113 // Called to change the extension's state when it is enabled/disabled. | 115 // Called to change the extension's state when it is enabled/disabled. |
114 void SetExtensionState(const std::string& extension_id, Extension::State); | 116 void SetExtensionState(const std::string& extension_id, Extension::State); |
115 | 117 |
116 // Returns all installed extensions | 118 // Returns all installed extensions |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 std::set<std::string> GetIdleInstallInfoIds(); | 299 std::set<std::string> GetIdleInstallInfoIds(); |
298 | 300 |
299 // We allow the web store to set a string containing login information when a | 301 // We allow the web store to set a string containing login information when a |
300 // purchase is made, so that when a user logs into sync with a different | 302 // purchase is made, so that when a user logs into sync with a different |
301 // account we can recognize the situation. The Get function returns true if | 303 // account we can recognize the situation. The Get function returns true if |
302 // there was previously stored data (placing it in |result|), or false | 304 // there was previously stored data (placing it in |result|), or false |
303 // otherwise. The Set will overwrite any previous login. | 305 // otherwise. The Set will overwrite any previous login. |
304 bool GetWebStoreLogin(std::string* result); | 306 bool GetWebStoreLogin(std::string* result); |
305 void SetWebStoreLogin(const std::string& login); | 307 void SetWebStoreLogin(const std::string& login); |
306 | 308 |
309 // Get the first page index StringOrdinal value. | |
310 StringOrdinal GetFirstAppPage(); | |
Dan Beam
2011/11/12 02:28:30
From style guide:
"Declare methods to be const wh
csharp
2011/11/14 16:22:28
Good point, I'd forgotten about this. The methods
| |
311 | |
312 // Create a StringOrdinal which will be the first element for the given page. | |
313 StringOrdinal CreateFirstAppLaunchIndex(const StringOrdinal& page_index); | |
314 | |
307 // Get the application launch index for an extension with |extension_id|. This | 315 // Get the application launch index for an extension with |extension_id|. This |
308 // determines the order of which the applications appear on the New Tab Page. | 316 // determines the order of which the applications appear on the New Tab Page. |
309 // A value of 0 generally indicates top left. If the extension has no launch | 317 // A value close to |A*| generally indicates top left. If the extension has no |
310 // index a -1 value is returned. | 318 // launch index a invalid StringOrdinal is returned. |
311 int GetAppLaunchIndex(const std::string& extension_id); | 319 StringOrdinal GetAppLaunchIndex(const std::string& extension_id); |
312 | 320 |
313 // Sets a specific launch index for an extension with |extension_id|. | 321 // Sets a specific launch index for an extension with |extension_id|. |
314 void SetAppLaunchIndex(const std::string& extension_id, int index); | 322 void SetAppLaunchIndex(const std::string& extension_id, |
323 const StringOrdinal& index); | |
315 | 324 |
316 // Gets the next available application launch index. This is 1 higher than the | 325 // Gets the next available application launch index. This is higher than the |
317 // highest current application launch index found for the page |on_page|. | 326 // highest current application launch index found for the page |on_page|. |
318 int GetNextAppLaunchIndex(int on_page); | 327 StringOrdinal GetNextAppLaunchIndex(StringOrdinal on_page); |
319 | 328 |
320 // Gets the page a new app should install to. Starts on page 0, and if there | 329 // Gets the page a new app should install to. Starts the first page, and if |
321 // are N or more apps on it, tries to install on the next page. | 330 // there are N or more apps on it, tries to install on the next page. |
322 int GetNaturalAppPageIndex(); | 331 StringOrdinal GetNaturalAppPageIndex(); |
323 | 332 |
324 // Sets the order the apps should be displayed in the app launcher. | 333 // Sets the order the apps should be displayed in the app launcher. |
325 void SetAppLauncherOrder(const std::vector<std::string>& extension_ids); | 334 void SetAppLauncherOrder(const std::vector<std::string>& extension_ids, |
335 const std::string& moved_extension_id); | |
326 | 336 |
327 // Get the application page index for an extension with |extension_id|. This | 337 // Get the application page index for an extension with |extension_id|. This |
328 // determines which page an app will appear on in page-based NTPs. If | 338 // determines which page an app will appear on in page-based NTPs. If |
329 // the app has no page specified, -1 is returned. | 339 // the app has no page specified, kUnsetIndex is returned. |
330 int GetPageIndex(const std::string& extension_id); | 340 StringOrdinal GetPageIndex(const std::string& extension_id); |
331 | 341 |
332 // Sets a specific page index for an extension with |extension_id|. | 342 // Sets a specific page index for an extension with |extension_id|. |
333 void SetPageIndex(const std::string& extension_id, int index); | 343 void SetPageIndex(const std::string& extension_id, |
344 const StringOrdinal& index); | |
334 | 345 |
335 // Removes the page index for an extension. | 346 // Removes the page index for an extension. |
336 void ClearPageIndex(const std::string& extension_id); | 347 void ClearPageIndex(const std::string& extension_id); |
337 | 348 |
349 // Convert the page index StringOrdinal value to its integer equivalent. | |
350 int PageIndexAsInteger(const StringOrdinal& page_index); | |
351 | |
352 // Converts the page index integer to its StringOrdinal equivalent. | |
353 StringOrdinal PageIndexAsStringOrdinal(size_t page_index); | |
354 | |
338 // Returns true if the user repositioned the app on the app launcher via drag | 355 // Returns true if the user repositioned the app on the app launcher via drag |
339 // and drop. | 356 // and drop. |
340 bool WasAppDraggedByUser(const std::string& extension_id); | 357 bool WasAppDraggedByUser(const std::string& extension_id); |
341 | 358 |
342 // Sets a flag indicating that the user repositioned the app on the app | 359 // Sets a flag indicating that the user repositioned the app on the app |
343 // launcher by drag and dropping it. | 360 // launcher by drag and dropping it. |
344 void SetAppDraggedByUser(const std::string& extension_id); | 361 void SetAppDraggedByUser(const std::string& extension_id); |
345 | 362 |
346 // The extension's update URL data. If not empty, the ExtensionUpdater | 363 // The extension's update URL data. If not empty, the ExtensionUpdater |
347 // will append a ap= parameter to the URL when checking if a new version | 364 // will append a ap= parameter to the URL when checking if a new version |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 // Reads an integer pref |pref_key| from extension with id |extension_id|. | 467 // Reads an integer pref |pref_key| from extension with id |extension_id|. |
451 bool ReadExtensionPrefInteger(const std::string& extension_id, | 468 bool ReadExtensionPrefInteger(const std::string& extension_id, |
452 const std::string& pref_key, | 469 const std::string& pref_key, |
453 int* out_value); | 470 int* out_value); |
454 | 471 |
455 // Reads a list pref |pref_key| from extension with id |extension_id|. | 472 // Reads a list pref |pref_key| from extension with id |extension_id|. |
456 bool ReadExtensionPrefList(const std::string& extension_id, | 473 bool ReadExtensionPrefList(const std::string& extension_id, |
457 const std::string& pref_key, | 474 const std::string& pref_key, |
458 const base::ListValue** out_value); | 475 const base::ListValue** out_value); |
459 | 476 |
477 // Reads a string pref |pref_key| from extension with id |extension_id| | |
478 bool ReadExtensionPrefString(const std::string& extension_id, | |
479 const std::string& pref_key, | |
480 std::string* out_value); | |
481 | |
460 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a | 482 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a |
461 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. | 483 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. |
462 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, | 484 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, |
463 const std::string& pref_key, | 485 const std::string& pref_key, |
464 URLPatternSet* result, | 486 URLPatternSet* result, |
465 int valid_schemes); | 487 int valid_schemes); |
466 | 488 |
467 // Converts |new_value| to a list of strings and sets the |pref_key| pref | 489 // Converts |new_value| to a list of strings and sets the |pref_key| pref |
468 // belonging to |extension_id|. | 490 // belonging to |extension_id|. |
469 void SetExtensionPrefURLPatternSet(const std::string& extension_id, | 491 void SetExtensionPrefURLPatternSet(const std::string& extension_id, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 // in a later Chrome version. | 529 // in a later Chrome version. |
508 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | 530 void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
509 | 531 |
510 // Installs the persistent extension preferences into |prefs_|'s extension | 532 // Installs the persistent extension preferences into |prefs_|'s extension |
511 // pref store. Does nothing if |extensions_disabled| is true. | 533 // pref store. Does nothing if |extensions_disabled| is true. |
512 void InitPrefStore(bool extensions_disabled); | 534 void InitPrefStore(bool extensions_disabled); |
513 | 535 |
514 // Migrates the permissions data in the pref store. | 536 // Migrates the permissions data in the pref store. |
515 void MigratePermissions(const ExtensionIdSet& extension_ids); | 537 void MigratePermissions(const ExtensionIdSet& extension_ids); |
516 | 538 |
539 // Migrates the app launcher and page index values. | |
540 void MigrateAppIndex(const ExtensionIdSet& extension_ids); | |
541 | |
517 // Checks whether there is a state pref for the extension and if so, whether | 542 // Checks whether there is a state pref for the extension and if so, whether |
518 // it matches |check_state|. | 543 // it matches |check_state|. |
519 bool DoesExtensionHaveState(const std::string& id, | 544 bool DoesExtensionHaveState(const std::string& id, |
520 Extension::State check_state) const; | 545 Extension::State check_state) const; |
521 | 546 |
547 // Searches though all loaded app and returns all the apps that appear on | |
548 // the page |page_index|. | |
549 void GetAllAppsOnPageSorted( | |
550 const StringOrdinal& page_index, | |
551 std::set<StringOrdinal, StringOrdinal::Comparsion>* indexs_on_page); | |
552 | |
553 // Initialize the page_index_map_ with the page indexes used by the | |
554 // given extensions. | |
555 void InitializePageIndexMap(const ExtensionIdSet& extension_ids); | |
556 | |
557 // Update a value in the page_index_map_. | |
558 void UpdatePageIndexMap(const StringOrdinal& old_value, | |
559 const StringOrdinal& new_value); | |
560 | |
522 // The pref service specific to this set of extension prefs. Owned by profile. | 561 // The pref service specific to this set of extension prefs. Owned by profile. |
523 PrefService* prefs_; | 562 PrefService* prefs_; |
524 | 563 |
525 // Base extensions install directory. | 564 // Base extensions install directory. |
526 FilePath install_directory_; | 565 FilePath install_directory_; |
527 | 566 |
567 // A map of all the StringOrdinal page indexs mapping to how often they are | |
568 // used, this is used for mapping the StringOrdinals to their integer | |
569 // equivalent as well as quick lookup of the sorted StringOrdinals. | |
570 std::map<StringOrdinal, int, StringOrdinal::Comparsion> page_index_map_; | |
571 | |
528 // Weak pointer, owned by Profile. | 572 // Weak pointer, owned by Profile. |
529 ExtensionPrefValueMap* extension_pref_value_map_; | 573 ExtensionPrefValueMap* extension_pref_value_map_; |
530 | 574 |
531 scoped_refptr<ExtensionContentSettingsStore> content_settings_store_; | 575 scoped_refptr<ExtensionContentSettingsStore> content_settings_store_; |
532 | 576 |
533 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 577 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
534 }; | 578 }; |
535 | 579 |
536 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 580 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
OLD | NEW |