Home | History | Annotate | Download | only in test
      1 // Copyright 2013 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 #include "chrome/browser/ui/app_list/test/fake_profile_store.h"
      6 
      7 #include "chrome/browser/profiles/profile.h"
      8 
      9 FakeProfileStore::FakeProfileStore(const base::FilePath& user_data_dir)
     10     : user_data_dir_(user_data_dir) {
     11 }
     12 
     13 FakeProfileStore::~FakeProfileStore() {
     14 }
     15 
     16 void FakeProfileStore::LoadProfile(Profile* profile) {
     17   loaded_profiles_[profile->GetPath()] = profile;
     18   CallbacksByPath::iterator it = callbacks_.find(profile->GetPath());
     19   if (it != callbacks_.end()) {
     20     it->second.Run(profile);
     21     callbacks_.erase(it);
     22   }
     23 }
     24 
     25 void FakeProfileStore::RemoveProfile(Profile* profile) {
     26   base::FilePath path(profile->GetPath());
     27   FOR_EACH_OBSERVER(ProfileInfoCacheObserver, observer_list_,
     28                     OnProfileWillBeRemoved(path));
     29   loaded_profiles_.erase(path);
     30   FOR_EACH_OBSERVER(ProfileInfoCacheObserver, observer_list_,
     31                     OnProfileWasRemoved(path, base::string16()));
     32 }
     33 
     34 void FakeProfileStore::AddProfileObserver(
     35     ProfileInfoCacheObserver* observer) {
     36   observer_list_.AddObserver(observer);
     37 }
     38 
     39 void FakeProfileStore::LoadProfileAsync(
     40     const base::FilePath& path,
     41     base::Callback<void(Profile*)> callback) {
     42   Profile* profile = GetProfileByPath(path);
     43   if (profile) {
     44     callback.Run(profile);
     45     return;
     46   }
     47   callbacks_[path] = callback;
     48 }
     49 
     50 Profile* FakeProfileStore::GetProfileByPath(
     51     const base::FilePath& path) {
     52   ProfilesByPath::const_iterator it = loaded_profiles_.find(path);
     53   if (it != loaded_profiles_.end())
     54     return it->second;
     55   return NULL;
     56 }
     57 
     58 base::FilePath FakeProfileStore::GetUserDataDir() {
     59   return user_data_dir_;
     60 }
     61 
     62 bool FakeProfileStore::IsProfileSupervised(const base::FilePath& path) {
     63   return false;
     64 }
     65