| Index: chrome/browser/extensions/api/browsing_data/browsing_data_api.cc
 | 
| diff --git a/chrome/browser/extensions/api/browsing_data/browsing_data_api.cc b/chrome/browser/extensions/api/browsing_data/browsing_data_api.cc
 | 
| index e8474db05fcc253855bbe04c2b52b9c134769905..b990296093917bd6d48a615b1c736787e66730f2 100644
 | 
| --- a/chrome/browser/extensions/api/browsing_data/browsing_data_api.cc
 | 
| +++ b/chrome/browser/extensions/api/browsing_data/browsing_data_api.cc
 | 
| @@ -8,13 +8,16 @@
 | 
|  
 | 
|  #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
 | 
|  
 | 
| +#include <set>
 | 
|  #include <string>
 | 
|  #include <utility>
 | 
|  
 | 
| +#include "base/stl_util.h"
 | 
|  #include "base/values.h"
 | 
|  #include "chrome/browser/browsing_data/browsing_data_helper.h"
 | 
|  #include "chrome/browser/browsing_data/browsing_data_remover.h"
 | 
|  #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
 | 
| +#include "chrome/browser/browsing_data/chrome_browsing_data_types.h"
 | 
|  #include "chrome/browser/plugins/plugin_data_remover_helper.h"
 | 
|  #include "chrome/browser/plugins/plugin_prefs.h"
 | 
|  #include "chrome/browser/profiles/profile.h"
 | 
| @@ -27,6 +30,7 @@
 | 
|  #include "extensions/common/extension.h"
 | 
|  
 | 
|  using content::BrowserThread;
 | 
| +using content::BrowsingDataType;
 | 
|  
 | 
|  namespace extension_browsing_data_api_constants {
 | 
|  
 | 
| @@ -69,51 +73,55 @@ const char kDeleteProhibitedError[] = "Browsing history and downloads are not "
 | 
|  }  // namespace extension_browsing_data_api_constants
 | 
|  
 | 
|  namespace {
 | 
| -int MaskForKey(const char* key) {
 | 
| +
 | 
| +// TODO(msramek): This function could be simplified to three lines if we ensured
 | 
| +// that extension API keys are the same as names specified in BrowsingDataType.
 | 
| +const BrowsingDataType* TypeForKey(const char* key) {
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kAppCacheKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_APPCACHE;
 | 
| +    return &kBrowsingDataTypeAppCache;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kCacheKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_CACHE;
 | 
| +    return &kBrowsingDataTypeCache;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kCookiesKey) == 0) {
 | 
| -    return BrowsingDataRemover::REMOVE_COOKIES;
 | 
| +    return &kBrowsingDataTypeCookies;
 | 
|    }
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kDownloadsKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_DOWNLOADS;
 | 
| +    return &kBrowsingDataTypeDownloads;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kFileSystemsKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_FILE_SYSTEMS;
 | 
| +    return &kBrowsingDataTypeFileSystems;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kFormDataKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_FORM_DATA;
 | 
| +    return &kBrowsingDataTypeFormData;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kHistoryKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_HISTORY;
 | 
| +    return &kBrowsingDataTypeHistory;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kIndexedDBKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_INDEXEDDB;
 | 
| +    return &kBrowsingDataTypeIndexedDB;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kLocalStorageKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_LOCAL_STORAGE;
 | 
| +    return &kBrowsingDataTypeLocalStorage;
 | 
|    if (strcmp(key,
 | 
|               extension_browsing_data_api_constants::kChannelIDsKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_CHANNEL_IDS;
 | 
| +    return &kBrowsingDataTypeChannelIDs;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kPasswordsKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_PASSWORDS;
 | 
| +    return &kBrowsingDataTypePasswords;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kPluginDataKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_PLUGIN_DATA;
 | 
| +    return &kBrowsingDataTypePluginData;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kServiceWorkersKey) ==
 | 
|        0)
 | 
| -    return BrowsingDataRemover::REMOVE_SERVICE_WORKERS;
 | 
| +    return &kBrowsingDataTypeServiceWorkers;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kCacheStorageKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_CACHE_STORAGE;
 | 
| +    return &kBrowsingDataTypeCacheStorage;
 | 
|    if (strcmp(key, extension_browsing_data_api_constants::kWebSQLKey) == 0)
 | 
| -    return BrowsingDataRemover::REMOVE_WEBSQL;
 | 
| +    return &kBrowsingDataTypeWebSQL;
 | 
|  
 | 
| -  return 0;
 | 
| +  return nullptr;
 | 
|  }
 | 
|  
 | 
|  // Returns false if any of the selected data types are not allowed to be
 | 
|  // deleted.
 | 
| -bool IsRemovalPermitted(int removal_mask, PrefService* prefs) {
 | 
| +bool IsRemovalPermitted(const std::set<const BrowsingDataType*>& removal_mask,
 | 
| +                        PrefService* prefs) {
 | 
|    // Enterprise policy or user preference might prohibit deleting browser or
 | 
|    // download history.
 | 
| -  if ((removal_mask & BrowsingDataRemover::REMOVE_HISTORY) ||
 | 
| -      (removal_mask & BrowsingDataRemover::REMOVE_DOWNLOADS)) {
 | 
| +  if (base::ContainsValue(removal_mask, &kBrowsingDataTypeHistory) ||
 | 
| +      base::ContainsValue(removal_mask, &kBrowsingDataTypeDownloads)) {
 | 
|      return prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
 | 
|    }
 | 
|    return true;
 | 
| @@ -227,7 +235,9 @@ void BrowsingDataSettingsFunction::SetDetails(
 | 
|      base::DictionaryValue* permitted_dict,
 | 
|      const char* data_type,
 | 
|      bool is_selected) {
 | 
| -  bool is_permitted = IsRemovalPermitted(MaskForKey(data_type), prefs_);
 | 
| +  const std::set<const BrowsingDataType*> removal_mask = {
 | 
| +      TypeForKey(data_type)};
 | 
| +  bool is_permitted = IsRemovalPermitted(removal_mask, prefs_);
 | 
|    selected_dict->SetBoolean(data_type, is_selected && is_permitted);
 | 
|    permitted_dict->SetBoolean(data_type, is_permitted);
 | 
|  }
 | 
| @@ -270,6 +280,7 @@ bool BrowsingDataRemoverFunction::RunAsync() {
 | 
|        base::Time::UnixEpoch() :
 | 
|        base::Time::FromDoubleT(ms_since_epoch / 1000.0);
 | 
|  
 | 
| +  removal_mask_.clear();
 | 
|    EXTENSION_FUNCTION_VALIDATE(GetRemovalMask(&removal_mask_));
 | 
|  
 | 
|    // Check for prohibited data types.
 | 
| @@ -278,7 +289,7 @@ bool BrowsingDataRemoverFunction::RunAsync() {
 | 
|      return false;
 | 
|    }
 | 
|  
 | 
| -  if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) {
 | 
| +  if (base::ContainsValue(removal_mask_, &kBrowsingDataTypePluginData)) {
 | 
|      // If we're being asked to remove plugin data, check whether it's actually
 | 
|      // supported.
 | 
|      BrowserThread::PostTask(
 | 
| @@ -301,7 +312,7 @@ BrowsingDataRemoverFunction::~BrowsingDataRemoverFunction() {}
 | 
|  void BrowsingDataRemoverFunction::CheckRemovingPluginDataSupported(
 | 
|      scoped_refptr<PluginPrefs> plugin_prefs) {
 | 
|    if (!PluginDataRemoverHelper::IsSupported(plugin_prefs.get()))
 | 
| -    removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
 | 
| +    removal_mask_.erase(&kBrowsingDataTypePluginData);
 | 
|  
 | 
|    BrowserThread::PostTask(
 | 
|        BrowserThread::UI, FROM_HERE,
 | 
| @@ -378,93 +389,108 @@ bool BrowsingDataRemoverFunction::ParseOriginTypeMask(
 | 
|  // Parses the |dataToRemove| argument to generate the removal mask.
 | 
|  // Returns false if parse was not successful, i.e. if 'dataToRemove' is not
 | 
|  // present or any data-type keys don't have supported (boolean) values.
 | 
| -bool BrowsingDataRemoveFunction::GetRemovalMask(int* removal_mask) {
 | 
| +bool BrowsingDataRemoveFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
|    base::DictionaryValue* data_to_remove;
 | 
|    if (!args_->GetDictionary(1, &data_to_remove))
 | 
|      return false;
 | 
|  
 | 
| -  *removal_mask = 0;
 | 
| +  removal_mask->clear();
 | 
|    for (base::DictionaryValue::Iterator i(*data_to_remove);
 | 
|         !i.IsAtEnd();
 | 
|         i.Advance()) {
 | 
|      bool selected = false;
 | 
|      if (!i.value().GetAsBoolean(&selected))
 | 
|        return false;
 | 
| -    if (selected)
 | 
| -      *removal_mask |= MaskForKey(i.key().c_str());
 | 
| +    const BrowsingDataType* data_type = TypeForKey(i.key().c_str());
 | 
| +    if (data_type && selected)
 | 
| +      removal_mask->insert(data_type);
 | 
|    }
 | 
|  
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveAppcacheFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_APPCACHE;
 | 
| +bool BrowsingDataRemoveAppcacheFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeAppCache);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveCacheFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_CACHE;
 | 
| +bool BrowsingDataRemoveCacheFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeCache);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveCookiesFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_COOKIES |
 | 
| -                  BrowsingDataRemover::REMOVE_CHANNEL_IDS;
 | 
| +bool BrowsingDataRemoveCookiesFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeCookies);
 | 
| +  removal_mask->insert(&kBrowsingDataTypeChannelIDs);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveDownloadsFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_DOWNLOADS;
 | 
| +bool BrowsingDataRemoveDownloadsFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeDownloads);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveFileSystemsFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_FILE_SYSTEMS;
 | 
| +bool BrowsingDataRemoveFileSystemsFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeFileSystems);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveFormDataFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_FORM_DATA;
 | 
| +bool BrowsingDataRemoveFormDataFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeFormData);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveHistoryFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_HISTORY;
 | 
| +bool BrowsingDataRemoveHistoryFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeHistory);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveIndexedDBFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_INDEXEDDB;
 | 
| +bool BrowsingDataRemoveIndexedDBFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeIndexedDB);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveLocalStorageFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_LOCAL_STORAGE;
 | 
| +bool BrowsingDataRemoveLocalStorageFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeLocalStorage);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemovePluginDataFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_PLUGIN_DATA;
 | 
| +bool BrowsingDataRemovePluginDataFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypePluginData);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemovePasswordsFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_PASSWORDS;
 | 
| +bool BrowsingDataRemovePasswordsFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypePasswords);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
|  bool BrowsingDataRemoveServiceWorkersFunction::GetRemovalMask(
 | 
| -    int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_SERVICE_WORKERS;
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeServiceWorkers);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveCacheStorageFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_CACHE_STORAGE;
 | 
| +bool BrowsingDataRemoveCacheStorageFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeCacheStorage);
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
| -bool BrowsingDataRemoveWebSQLFunction::GetRemovalMask(int* removal_mask) {
 | 
| -  *removal_mask = BrowsingDataRemover::REMOVE_WEBSQL;
 | 
| +bool BrowsingDataRemoveWebSQLFunction::GetRemovalMask(
 | 
| +    std::set<const BrowsingDataType*>* removal_mask) {
 | 
| +  removal_mask->insert(&kBrowsingDataTypeWebSQL);
 | 
|    return true;
 | 
|  }
 | 
| 
 |