profile_helper.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
1// Copyright (c) 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#ifndef CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ 6#define CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/callback_forward.h" 13#include "base/files/file_path.h" 14#include "chrome/browser/browsing_data/browsing_data_remover.h" 15#include "chrome/browser/chromeos/login/user_manager.h" 16 17class Profile; 18 19namespace chromeos { 20 21class ProfileHelper : public BrowsingDataRemover::Observer, 22 public UserManager::UserSessionStateObserver { 23 public: 24 // Chrome OS profile directories have custom prefix. 25 // Profile path format: [user_data_dir]/u-[$hash] 26 // Ex.: /home/chronos/u-0123456789 27 static const char kProfileDirPrefix[]; 28 29 ProfileHelper(); 30 virtual ~ProfileHelper(); 31 32 // Returns Profile instance that corresponds to |user_id_hash|. 33 static Profile* GetProfileByUserIdHash(const std::string& user_id_hash); 34 35 // Returns OffTheRecord profile for use during signing phase. 36 static Profile* GetSigninProfile(); 37 38 // Returns user_id hash for |profile| instance or empty string if hash 39 // could not be extracted from |profile|. 40 static std::string GetUserIdHashFromProfile(Profile* profile); 41 42 // Returns true if |profile| is the signin Profile. This can be used during 43 // construction of the signin Profile to determine if that Profile is the 44 // signin Profile. 45 static bool IsSigninProfile(Profile* profile); 46 47 // Initialize a bunch of services that are tied to a browser profile. 48 // TODO(dzhioev): Investigate whether or not this method is needed. 49 static void ProfileStartup(Profile* profile, bool process_startup); 50 51 // Returns active user profile dir in a format [u-$hash]. 52 base::FilePath GetActiveUserProfileDir(); 53 54 // Should called once after UserManager instance has been created. 55 void Initialize(); 56 57 // Returns hash for active user ID which is used to identify that user profile 58 // on Chrome OS. 59 std::string active_user_id_hash() { return active_user_id_hash_; } 60 61 // Clears site data (cookies, history, etc) for signin profile. 62 // Callback can be empty. Not thread-safe. 63 void ClearSigninProfile(const base::Closure& on_clear_callback); 64 65 private: 66 friend class ProfileHelperTest; 67 68 // UserManager::UserSessionStateObserver implementation: 69 virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE; 70 71 // BrowsingDataRemover::Observer implementation: 72 virtual void OnBrowsingDataRemoverDone() OVERRIDE; 73 74 // Identifies path to active user profile on Chrome OS. 75 std::string active_user_id_hash_; 76 77 // True if signin profile clearing now. 78 bool signin_profile_clear_requested_; 79 80 // List of callbacks called after signin profile clearance. 81 std::vector<base::Closure> on_clear_callbacks_; 82 83 DISALLOW_COPY_AND_ASSIGN(ProfileHelper); 84}; 85 86} // namespace chromeos 87 88#endif // CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ 89 90