1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This class keeps track of the currently-active profiles in the runtime.
#ifndef CHROME_BROWSER_PROFILE_MANAGER_H__
#define CHROME_BROWSER_PROFILE_MANAGER_H__
#pragma once
#include <vector>
#include "app/system_monitor.h"
#include "base/basictypes.h"
#include "base/message_loop.h"
#include "base/non_thread_safe.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
class FilePath;
class ProfileManager : public NonThreadSafe,
public SystemMonitor::PowerObserver,
public NotificationObserver {
public:
ProfileManager();
virtual ~ProfileManager();
// Invokes ShutdownSessionService() on all profiles.
static void ShutdownSessionServices();
// Returns the default profile. This adds the profile to the
// ProfileManager if it doesn't already exist. This method returns NULL if
// the profile doesn't exist and we can't create it.
// The profile used can be overridden by using --login-profile on cros.
Profile* GetDefaultProfile(const FilePath& user_data_dir);
// Same as instance method but provides the default user_data_dir as well.
static Profile* GetDefaultProfile();
// Returns a profile for a specific profile directory within the user data
// dir. This will return an existing profile it had already been created,
// otherwise it will create and manage it.
Profile* GetProfile(const FilePath& profile_dir);
// Returns a profile for a specific profile directory within the user data
// dir with the option of controlling whether extensions are initialized
// or not. This will return an existing profile it had already been created,
// otherwise it will create and manage it.
// Note that if the profile has already been created, extensions may have
// been initialized. If this matters to you, you should call GetProfileByPath
// first to see if the profile already exists.
Profile* GetProfile(const FilePath& profile_dir, bool init_extensions);
// Returns the directory where the currently active profile is
// stored, relative to the user data directory currently in use..
FilePath GetCurrentProfileDir();
// These allow iteration through the current list of profiles.
typedef std::vector<Profile*> ProfileVector;
typedef ProfileVector::iterator iterator;
typedef ProfileVector::const_iterator const_iterator;
iterator begin() { return profiles_.begin(); }
const_iterator begin() const { return profiles_.begin(); }
iterator end() { return profiles_.end(); }
const_iterator end() const { return profiles_.end(); }
// PowerObserver notifications
void OnSuspend();
void OnResume();
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// ------------------ static utility functions -------------------
// Returns the path to the default profile directory, based on the given
// user data directory.
static FilePath GetDefaultProfileDir(const FilePath& user_data_dir);
// Returns the path to the preferences file given the user profile directory.
static FilePath GetProfilePrefsPath(const FilePath& profile_dir);
// Tries to determine whether the given path represents a profile
// directory, and returns true if it thinks it does.
static bool IsProfile(const FilePath& path);
// If a profile with the given path is currently managed by this object,
// return a pointer to the corresponding Profile object;
// otherwise return NULL.
Profile* GetProfileByPath(const FilePath& path) const;
// Creates a new profile at the specified path.
// This method should always return a valid Profile (i.e., should never
// return NULL).
static Profile* CreateProfile(const FilePath& path);
private:
// Hooks to suspend/resume per-profile network traffic.
// These must be called on the IO thread.
static void SuspendProfile(Profile*);
static void ResumeProfile(Profile*);
// Adds a pre-existing Profile object to the set managed by this
// ProfileManager. This ProfileManager takes ownership of the Profile.
// The Profile should not already be managed by this ProfileManager.
// Returns true if the profile was added, false otherwise.
bool AddProfile(Profile* profile, bool init_extensions);
// We keep a simple vector of profiles rather than something fancier
// because we expect there to be a small number of profiles active.
ProfileVector profiles_;
NotificationRegistrar registrar_;
// Indicates that a user has logged in and that the profile specified
// in the --login-profile command line argument should be used as the
// default.
bool logged_in_;
DISALLOW_COPY_AND_ASSIGN(ProfileManager);
};
#endif // CHROME_BROWSER_PROFILE_MANAGER_H__
|