summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 16:09:23 +0000
committeryukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 16:09:23 +0000
commit7b7e0b30cd44d9d714032a6f4e51d3963951731e (patch)
tree3b05bac48deae075e0154ce14a986310546c7c25
parent64bd053812a43ec74755dfc1de4e2b4869a87360 (diff)
downloadchromium_src-7b7e0b30cd44d9d714032a6f4e51d3963951731e.zip
chromium_src-7b7e0b30cd44d9d714032a6f4e51d3963951731e.tar.gz
chromium_src-7b7e0b30cd44d9d714032a6f4e51d3963951731e.tar.bz2
Allows the guest session on CrOS to load extension resource.
The current implementation inhibits extensions to load resources if it's in incognito mode and the extension is not enabled for incognito mode. That's right in a regular (non-guest) session. However, the guest session is in incognito mode by default, and it doesn't have a regular (non-incognito) context. So we should allow resource loading if it's the guest session, otherwise there is no way for component extensions to load resources. Note component extensions are never listed in the extension list, so users cannot enable those extensions for incognito mode. BUG=339318 TEST=Manually done. TBR=davemoore@chromium.org Review URL: https://codereview.chromium.org/182493004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257437 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/shell/browser/shell_content_browser_client.cc2
-rw-r--r--chrome/browser/apps/app_url_redirector.cc2
-rw-r--r--chrome/browser/apps/ephemeral_app_throttle.cc2
-rw-r--r--chrome/browser/extensions/extension_protocols.cc19
-rw-r--r--chrome/browser/extensions/extension_protocols.h3
-rw-r--r--chrome/browser/extensions/extension_protocols_unittest.cc13
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc34
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl_unittest.cc1
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.cc8
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.h2
-rw-r--r--chrome/browser/profiles/profile.h9
-rw-r--r--chrome/browser/profiles/profile_impl.cc4
-rw-r--r--chrome/browser/profiles/profile_impl.h1
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc2
-rw-r--r--chrome/browser/profiles/profile_io_data.cc21
-rw-r--r--chrome/browser/profiles/profile_io_data.h12
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc11
-rw-r--r--chrome/browser/signin/signin_header_helper.cc10
-rw-r--r--chrome/browser/ui/app_list/test/fake_profile.cc4
-rw-r--r--chrome/browser/ui/app_list/test/fake_profile.h1
-rw-r--r--chrome/browser/ui/sync/one_click_signin_helper.cc2
-rw-r--r--chrome/browser/ui/sync/one_click_signin_helper_unittest.cc43
-rw-r--r--chrome/test/base/testing_profile.cc8
-rw-r--r--chrome/test/base/testing_profile.h3
25 files changed, 148 insertions, 73 deletions
diff --git a/apps/shell/browser/shell_content_browser_client.cc b/apps/shell/browser/shell_content_browser_client.cc
index e5260d0..73eda6e 100644
--- a/apps/shell/browser/shell_content_browser_client.cc
+++ b/apps/shell/browser/shell_content_browser_client.cc
@@ -69,7 +69,7 @@ net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext(
browser_main_parts_->extension_system()->info_map();
(*protocol_handlers)[extensions::kExtensionScheme] =
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
- CreateExtensionProtocolHandler(false /*is_incognito*/,
+ CreateExtensionProtocolHandler(Profile::REGULAR_PROFILE,
extension_info_map));
(*protocol_handlers)[extensions::kExtensionResourceScheme] =
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
diff --git a/chrome/browser/apps/app_url_redirector.cc b/chrome/browser/apps/app_url_redirector.cc
index e622f14..85652cf 100644
--- a/chrome/browser/apps/app_url_redirector.cc
+++ b/chrome/browser/apps/app_url_redirector.cc
@@ -92,7 +92,7 @@ AppUrlRedirector::MaybeCreateThrottleFor(net::URLRequest* request,
// Never redirect URLs to apps in incognito. Technically, apps are not
// supported in incognito, but that may change in future.
// See crbug.com/240879, which tracks incognito support for v2 apps.
- if (profile_io_data->is_incognito()) {
+ if (profile_io_data->IsOffTheRecord()) {
DVLOG(1) << "Skip redirection: unsupported in incognito";
return NULL;
}
diff --git a/chrome/browser/apps/ephemeral_app_throttle.cc b/chrome/browser/apps/ephemeral_app_throttle.cc
index 1ebdd3b..be398cb 100644
--- a/chrome/browser/apps/ephemeral_app_throttle.cc
+++ b/chrome/browser/apps/ephemeral_app_throttle.cc
@@ -72,7 +72,7 @@ EphemeralAppThrottle::MaybeCreateThrottleForLaunch(
return NULL;
// Not supported for incognito profiles.
- if (profile_io_data->is_incognito())
+ if (profile_io_data->IsOffTheRecord())
return NULL;
// Only watch for links in Google search results.
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index 7d5735a..e3e9865 100644
--- a/chrome/browser/extensions/extension_protocols.cc
+++ b/chrome/browser/extensions/extension_protocols.cc
@@ -364,7 +364,7 @@ bool ExtensionCanLoadInIncognito(const ResourceRequestInfo* info,
// TODO(aa): This should be moved into ExtensionResourceRequestPolicy, but we
// first need to find a way to get CanLoadInIncognito state into the renderers.
bool AllowExtensionResourceLoad(net::URLRequest* request,
- bool is_incognito,
+ Profile::ProfileType profile_type,
const Extension* extension,
extensions::InfoMap* extension_info_map) {
const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
@@ -377,8 +377,9 @@ bool AllowExtensionResourceLoad(net::URLRequest* request,
return true;
}
- if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(),
- extension_info_map)) {
+ if (profile_type == Profile::INCOGNITO_PROFILE &&
+ !ExtensionCanLoadInIncognito(info, request->url().host(),
+ extension_info_map)) {
return false;
}
@@ -486,9 +487,9 @@ bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) {
class ExtensionProtocolHandler
: public net::URLRequestJobFactory::ProtocolHandler {
public:
- ExtensionProtocolHandler(bool is_incognito,
+ ExtensionProtocolHandler(Profile::ProfileType profile_type,
extensions::InfoMap* extension_info_map)
- : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {}
+ : profile_type_(profile_type), extension_info_map_(extension_info_map) {}
virtual ~ExtensionProtocolHandler() {}
@@ -497,7 +498,7 @@ class ExtensionProtocolHandler
net::NetworkDelegate* network_delegate) const OVERRIDE;
private:
- const bool is_incognito_;
+ const Profile::ProfileType profile_type_;
extensions::InfoMap* const extension_info_map_;
DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler);
};
@@ -513,7 +514,7 @@ ExtensionProtocolHandler::MaybeCreateJob(
// TODO(mpcomplete): better error code.
if (!AllowExtensionResourceLoad(
- request, is_incognito_, extension, extension_info_map_)) {
+ request, profile_type_, extension, extension_info_map_)) {
return new net::URLRequestErrorJob(
request, network_delegate, net::ERR_ADDRESS_UNREACHABLE);
}
@@ -638,7 +639,7 @@ ExtensionProtocolHandler::MaybeCreateJob(
} // namespace
net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
- bool is_incognito,
+ Profile::ProfileType profile_type,
extensions::InfoMap* extension_info_map) {
- return new ExtensionProtocolHandler(is_incognito, extension_info_map);
+ return new ExtensionProtocolHandler(profile_type, extension_info_map);
}
diff --git a/chrome/browser/extensions/extension_protocols.h b/chrome/browser/extensions/extension_protocols.h
index 1cc8f1c..ffef9d1 100644
--- a/chrome/browser/extensions/extension_protocols.h
+++ b/chrome/browser/extensions/extension_protocols.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROTOCOLS_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROTOCOLS_H_
+#include "chrome/browser/profiles/profile.h"
#include "net/url_request/url_request_job_factory.h"
namespace extensions {
@@ -13,7 +14,7 @@ class InfoMap;
// Creates the handlers for the chrome-extension:// scheme.
net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
- bool is_incognito,
+ Profile::ProfileType profile_type,
extensions::InfoMap* extension_info_map);
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROTOCOLS_H_
diff --git a/chrome/browser/extensions/extension_protocols_unittest.cc b/chrome/browser/extensions/extension_protocols_unittest.cc
index a39a89a..fd9d82a 100644
--- a/chrome/browser/extensions/extension_protocols_unittest.cc
+++ b/chrome/browser/extensions/extension_protocols_unittest.cc
@@ -106,12 +106,13 @@ class ExtensionProtocolTest : public testing::Test {
request_context->set_job_factory(old_factory_);
}
- void SetProtocolHandler(bool incognito) {
+ void SetProtocolHandler(Profile::ProfileType profile_type) {
net::URLRequestContext* request_context =
resource_context_.GetRequestContext();
job_factory_.SetProtocolHandler(
kExtensionScheme,
- CreateExtensionProtocolHandler(incognito, extension_info_map_.get()));
+ CreateExtensionProtocolHandler(profile_type,
+ extension_info_map_.get()));
request_context->set_job_factory(&job_factory_);
}
@@ -144,7 +145,7 @@ class ExtensionProtocolTest : public testing::Test {
// extension).
TEST_F(ExtensionProtocolTest, IncognitoRequest) {
// Register an incognito extension protocol handler.
- SetProtocolHandler(true);
+ SetProtocolHandler(Profile::INCOGNITO_PROFILE);
struct TestCase {
// Inputs.
@@ -223,7 +224,7 @@ void CheckForContentLengthHeader(net::URLRequest* request) {
// the extension is enabled and when it is disabled.
TEST_F(ExtensionProtocolTest, ComponentResourceRequest) {
// Register a non-incognito extension protocol handler.
- SetProtocolHandler(false);
+ SetProtocolHandler(Profile::REGULAR_PROFILE);
scoped_refptr<Extension> extension = CreateWebStoreExtension();
extension_info_map_->AddExtension(extension.get(),
@@ -260,7 +261,7 @@ TEST_F(ExtensionProtocolTest, ComponentResourceRequest) {
// expected response headers.
TEST_F(ExtensionProtocolTest, ResourceRequestResponseHeaders) {
// Register a non-incognito extension protocol handler.
- SetProtocolHandler(false);
+ SetProtocolHandler(Profile::REGULAR_PROFILE);
scoped_refptr<Extension> extension = CreateTestResponseHeaderExtension();
extension_info_map_->AddExtension(extension.get(),
@@ -298,7 +299,7 @@ TEST_F(ExtensionProtocolTest, ResourceRequestResponseHeaders) {
// succeeds, but subresources fail. See http://crbug.com/312269.
TEST_F(ExtensionProtocolTest, AllowFrameRequests) {
// Register a non-incognito extension protocol handler.
- SetProtocolHandler(false);
+ SetProtocolHandler(Profile::REGULAR_PROFILE);
scoped_refptr<Extension> extension = CreateTestExtension("foo", false);
extension_info_map_->AddExtension(extension.get(),
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 810de68..b73a0ec 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -97,13 +97,19 @@ void NotifyOTRProfileDestroyedOnIOThread(void* original_profile,
OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile)
: profile_(real_profile),
prefs_(PrefServiceSyncable::IncognitoFromProfile(real_profile)),
- io_data_(this),
start_time_(Time::Now()) {
// Register on BrowserContext.
user_prefs::UserPrefs::Set(this, prefs_);
}
void OffTheRecordProfileImpl::Init() {
+ // The construction of OffTheRecordProfileIOData::Handle needs the profile
+ // type returned by this->GetProfileType(). Since GetProfileType() is a
+ // virtual member function, we cannot call the function defined in the most
+ // derived class (e.g. GuestSessionProfile) until a ctor finishes. Thus,
+ // we have to instantiate OffTheRecordProfileIOData::Handle here after a ctor.
+ InitIoData();
+
#if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
// Because UserCloudPolicyManager is in a component, it cannot access
// GetOriginalProfile. Instead, we have to inject this relation here.
@@ -139,7 +145,7 @@ void OffTheRecordProfileImpl::Init() {
#if defined(ENABLE_PLUGINS)
ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
PluginPrefs::GetForProfile(this).get(),
- io_data_.GetResourceContextNoInit());
+ io_data_->GetResourceContextNoInit());
#endif
BrowserThread::PostTask(
@@ -152,7 +158,7 @@ OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
#if defined(ENABLE_PLUGINS)
ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
- io_data_.GetResourceContextNoInit());
+ io_data_->GetResourceContextNoInit());
#endif
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
@@ -173,6 +179,10 @@ OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
g_browser_process->io_thread()->ChangedToOnTheRecord();
}
+void OffTheRecordProfileImpl::InitIoData() {
+ io_data_.reset(new OffTheRecordProfileIOData::Handle(this));
+}
+
void OffTheRecordProfileImpl::InitHostZoomMap() {
HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
HostZoomMap* parent_host_zoom_map =
@@ -206,6 +216,10 @@ std::string OffTheRecordProfileImpl::GetProfileName() {
return std::string();
}
+Profile::ProfileType OffTheRecordProfileImpl::GetProfileType() const {
+ return INCOGNITO_PROFILE;
+}
+
base::FilePath OffTheRecordProfileImpl::GetPath() const {
return profile_->GetPath();
}
@@ -269,7 +283,7 @@ net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() {
net::URLRequestContextGetter* OffTheRecordProfileImpl::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) {
- return io_data_.CreateMainRequestContextGetter(
+ return io_data_->CreateMainRequestContextGetter(
protocol_handlers, protocol_interceptors.Pass()).get();
}
@@ -298,7 +312,7 @@ net::URLRequestContextGetter*
OffTheRecordProfileImpl::GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
- return io_data_.GetIsolatedAppRequestContextGetter(partition_path, in_memory)
+ return io_data_->GetIsolatedAppRequestContextGetter(partition_path, in_memory)
.get();
}
@@ -363,7 +377,7 @@ void OffTheRecordProfileImpl::CancelProtectedMediaIdentifierPermissionRequests(
net::URLRequestContextGetter*
OffTheRecordProfileImpl::GetRequestContextForExtensions() {
- return io_data_.GetExtensionsRequestContextGetter().get();
+ return io_data_->GetExtensionsRequestContextGetter().get();
}
net::URLRequestContextGetter*
@@ -372,7 +386,7 @@ OffTheRecordProfileImpl::CreateRequestContextForStoragePartition(
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) {
- return io_data_.CreateIsolatedAppRequestContextGetter(
+ return io_data_->CreateIsolatedAppRequestContextGetter(
partition_path,
in_memory,
protocol_handlers,
@@ -380,7 +394,7 @@ OffTheRecordProfileImpl::CreateRequestContextForStoragePartition(
}
content::ResourceContext* OffTheRecordProfileImpl::GetResourceContext() {
- return io_data_.GetResourceContext();
+ return io_data_->GetResourceContext();
}
net::SSLConfigService* OffTheRecordProfileImpl::GetSSLConfigService() {
@@ -504,6 +518,10 @@ class GuestSessionProfile : public OffTheRecordProfileImpl {
: OffTheRecordProfileImpl(real_profile) {
}
+ virtual ProfileType GetProfileType() const OVERRIDE {
+ return GUEST_PROFILE;
+ }
+
virtual void InitChromeOSPreferences() OVERRIDE {
chromeos_preferences_.reset(new chromeos::Preferences());
chromeos_preferences_->Init(static_cast<PrefServiceSyncable*>(GetPrefs()),
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index c0f4240..41577b1 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -36,6 +36,7 @@ class OffTheRecordProfileImpl : public Profile {
// Profile implementation.
virtual std::string GetProfileName() OVERRIDE;
+ virtual ProfileType GetProfileType() const OVERRIDE;
virtual Profile* GetOffTheRecordProfile() OVERRIDE;
virtual void DestroyOffTheRecordProfile() OVERRIDE;
virtual bool HasOffTheRecordProfile() OVERRIDE;
@@ -126,6 +127,7 @@ class OffTheRecordProfileImpl : public Profile {
private:
FRIEND_TEST_ALL_PREFIXES(OffTheRecordProfileImplTest, GetHostZoomMap);
+ void InitIoData();
void InitHostZoomMap();
#if defined(OS_ANDROID) || defined(OS_IOS)
@@ -141,7 +143,7 @@ class OffTheRecordProfileImpl : public Profile {
// Weak pointer owned by |profile_|.
PrefServiceSyncable* prefs_;
- OffTheRecordProfileIOData::Handle io_data_;
+ scoped_ptr<OffTheRecordProfileIOData::Handle> io_data_;
// We use a non-persistent content settings map for OTR.
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
diff --git a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
index ac893d3..236daf80 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
@@ -148,6 +148,7 @@ TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) {
// Prepare child profile as off the record profile.
scoped_ptr<OffTheRecordProfileImpl> child_profile(
new OffTheRecordProfileImpl(parent_profile.get()));
+ child_profile->InitIoData();
child_profile->InitHostZoomMap();
BrowserContextDependencyManager::GetInstance()->
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc
index 1697d09..b0f7f6c 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -41,7 +41,7 @@
using content::BrowserThread;
OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
- : io_data_(new OffTheRecordProfileIOData),
+ : io_data_(new OffTheRecordProfileIOData(profile->GetProfileType())),
profile_(profile),
initialized_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -159,8 +159,10 @@ void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
io_data_->InitializeOnUIThread(profile_);
}
-OffTheRecordProfileIOData::OffTheRecordProfileIOData()
- : ProfileIOData(true) {}
+OffTheRecordProfileIOData::OffTheRecordProfileIOData(
+ Profile::ProfileType profile_type)
+ : ProfileIOData(profile_type) {}
+
OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {
DestroyResourceContext();
}
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h
index cfeda5f..789fffd 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.h
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.h
@@ -100,7 +100,7 @@ class OffTheRecordProfileIOData : public ProfileIOData {
private:
friend class base::RefCountedThreadSafe<OffTheRecordProfileIOData>;
- OffTheRecordProfileIOData();
+ explicit OffTheRecordProfileIOData(Profile::ProfileType profile_type);
virtual ~OffTheRecordProfileIOData();
virtual void InitializeInternal(
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 6b0104e..6696257 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -130,6 +130,12 @@ class Profile : public content::BrowserContext {
EXIT_CRASHED,
};
+ enum ProfileType {
+ REGULAR_PROFILE, // Login user's normal profile
+ INCOGNITO_PROFILE, // Login user's off-the-record profile
+ GUEST_PROFILE, // Guest session's profile
+ };
+
class Delegate {
public:
virtual ~Delegate();
@@ -175,6 +181,9 @@ class Profile : public content::BrowserContext {
// the browser frame.
virtual std::string GetProfileName() = 0;
+ // Returns the profile type.
+ virtual ProfileType GetProfileType() const = 0;
+
// Return the incognito version of this profile. The returned pointer
// is owned by the receiving profile. If the receiving profile is off the
// record, the same profile is returned.
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 10908f5..18c0bd1 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -723,6 +723,10 @@ std::string ProfileImpl::GetProfileName() {
return GetPrefs()->GetString(prefs::kGoogleServicesUsername);
}
+Profile::ProfileType ProfileImpl::GetProfileType() const {
+ return REGULAR_PROFILE;
+}
+
base::FilePath ProfileImpl::GetPath() const {
return path_;
}
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 11a8b36..6d2ba79 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -104,6 +104,7 @@ class ProfileImpl : public Profile {
// Note that this implementation returns the Google-services username, if any,
// not the Chrome user's display name.
virtual std::string GetProfileName() OVERRIDE;
+ virtual ProfileType GetProfileType() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual Profile* GetOffTheRecordProfile() OVERRIDE;
virtual void DestroyOffTheRecordProfile() OVERRIDE;
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index 4011cf3..9649f41 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -336,7 +336,7 @@ ProfileImplIOData::LazyParams::LazyParams()
ProfileImplIOData::LazyParams::~LazyParams() {}
ProfileImplIOData::ProfileImplIOData()
- : ProfileIOData(false),
+ : ProfileIOData(Profile::REGULAR_PROFILE),
http_server_properties_manager_(NULL),
app_cache_max_size_(0),
app_media_cache_max_size_(0) {
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index 25e91d1..fd5a029 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -385,7 +385,7 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
// These members are used only for one click sign in, which is not enabled
// in incognito mode. So no need to initialize them.
- if (!is_incognito()) {
+ if (!IsOffTheRecord()) {
signin_names_.reset(new SigninNamesOnIOThread());
google_services_user_account_id_.Init(
@@ -419,7 +419,7 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
local_state_pref_service);
quick_check_enabled_.MoveToThread(io_message_loop_proxy);
- media_device_id_salt_ = new MediaDeviceIDSalt(pref_service, is_incognito());
+ media_device_id_salt_ = new MediaDeviceIDSalt(pref_service, IsOffTheRecord());
network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled,
pref_service);
@@ -447,7 +447,7 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
callback,
policy::OverrideBlacklistForURL));
- if (!is_incognito()) {
+ if (!IsOffTheRecord()) {
// Add policy headers for non-incognito requests.
policy::PolicyHeaderService* policy_header_service =
policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile);
@@ -507,11 +507,11 @@ ProfileIOData::ProfileParams::ProfileParams()
ProfileIOData::ProfileParams::~ProfileParams() {}
-ProfileIOData::ProfileIOData(bool is_incognito)
+ProfileIOData::ProfileIOData(Profile::ProfileType profile_type)
: initialized_(false),
resource_context_(new ResourceContext(this)),
initialized_on_UI_thread_(false),
- is_incognito_(is_incognito) {
+ profile_type_(profile_type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -737,6 +737,11 @@ ResourceContext::SaltCallback ProfileIOData::GetMediaDeviceIDSalt() const {
return base::Bind(&MediaDeviceIDSalt::GetSalt, media_device_id_salt_);
}
+bool ProfileIOData::IsOffTheRecord() const {
+ return profile_type() == Profile::INCOGNITO_PROFILE
+ || profile_type() == Profile::GUEST_PROFILE;
+}
+
void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
#if defined(OS_CHROMEOS)
@@ -960,7 +965,7 @@ void ProfileIOData::Init(
transport_security_state_.get(),
profile_params_->path,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
- is_incognito()));
+ IsOffTheRecord()));
// Take ownership over these parameters.
cookie_settings_ = profile_params_->cookie_settings;
@@ -1032,7 +1037,7 @@ scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
DCHECK(extension_info_map_.get());
set_protocol = job_factory->SetProtocolHandler(
extensions::kExtensionScheme,
- CreateExtensionProtocolHandler(is_incognito(),
+ CreateExtensionProtocolHandler(profile_type(),
extension_info_map_.get()));
DCHECK(set_protocol);
set_protocol = job_factory->SetProtocolHandler(
@@ -1043,7 +1048,7 @@ scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
content::kDataScheme, new net::DataProtocolHandler());
DCHECK(set_protocol);
#if defined(OS_CHROMEOS)
- if (!is_incognito() && profile_params_) {
+ if (!IsOffTheRecord() && profile_params_) {
set_protocol = job_factory->SetProtocolHandler(
chrome::kDriveScheme,
new drive::DriveProtocolHandler(profile_params_->profile));
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index d849d28..af2f3a3 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -18,6 +18,7 @@
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
#include "chrome/common/content_settings_types.h"
#include "content/public/browser/content_browser_client.h"
@@ -32,7 +33,6 @@ class CookieSettings;
class HostContentSettingsMap;
class ManagedModeURLFilter;
class MediaDeviceIDSalt;
-class Profile;
class ProtocolHandlerRegistry;
class SigninNamesOnIOThread;
@@ -189,10 +189,12 @@ class ProfileIOData {
}
#endif
- bool is_incognito() const {
- return is_incognito_;
+ Profile::ProfileType profile_type() const {
+ return profile_type_;
}
+ bool IsOffTheRecord() const;
+
#if defined(ENABLE_CONFIGURATION_POLICY)
policy::PolicyHeaderIOHelper* policy_header_helper() const {
return policy_header_helper_.get();
@@ -294,7 +296,7 @@ class ProfileIOData {
void* profile;
};
- explicit ProfileIOData(bool is_incognito);
+ explicit ProfileIOData(Profile::ProfileType profile_type);
static std::string GetSSLSessionCacheShard();
@@ -553,7 +555,7 @@ class ProfileIOData {
// TODO(jhawkins): Remove once crbug.com/102004 is fixed.
bool initialized_on_UI_thread_;
- bool is_incognito_;
+ const Profile::ProfileType profile_type_;
DISALLOW_COPY_AND_ASSIGN(ProfileIOData);
};
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index c98d347..c1c3126 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -361,11 +361,12 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
if (!request->is_pending()) {
net::HttpRequestHeaders headers;
headers.CopyFrom(request->extra_request_headers());
- bool incognito = io_data->is_incognito();
+ bool is_off_the_record = io_data->IsOffTheRecord();
chrome_variations::VariationsHttpHeaderProvider::GetInstance()->
AppendHeaders(request->url(),
- incognito,
- !incognito && io_data->GetMetricsEnabledStateOnIOThread(),
+ is_off_the_record,
+ !is_off_the_record &&
+ io_data->GetMetricsEnabledStateOnIOThread(),
&headers);
request->SetExtraRequestHeaders(headers);
}
@@ -542,7 +543,7 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
#if !defined(OS_ANDROID)
ProfileIOData* io_data =
ProfileIOData::FromResourceContext(resource_context);
- bool profile_is_incognito = io_data->is_incognito();
+ bool profile_is_off_the_record = io_data->IsOffTheRecord();
const scoped_refptr<const extensions::InfoMap> extension_info_map(
io_data->GetExtensionInfoMap());
std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
@@ -555,7 +556,7 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
// The white-listed extension may not be installed, so we have to NULL check
// |extension|.
if (!extension ||
- (profile_is_incognito &&
+ (profile_is_off_the_record &&
!extension_info_map->IsIncognitoEnabled(extension_id))) {
continue;
}
diff --git a/chrome/browser/signin/signin_header_helper.cc b/chrome/browser/signin/signin_header_helper.cc
index 4ed03cd..22140c6 100644
--- a/chrome/browser/signin/signin_header_helper.cc
+++ b/chrome/browser/signin/signin_header_helper.cc
@@ -68,10 +68,10 @@ void AppendMirrorRequestHeaderIfPossible(
int route_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- if (io_data->is_incognito() ||
- io_data->google_services_username()->GetValue().empty()) {
- return;
- }
+ if (io_data->IsOffTheRecord() ||
+ io_data->google_services_username()->GetValue().empty()) {
+ return;
+ }
// Only set the header for Drive always, and other Google properties if
// new-profile-management is enabled.
@@ -119,7 +119,7 @@ void ProcessMirrorResponseHeaderIfExists(
if (gaia::IsGaiaSignonRealm(request->url().GetOrigin()) &&
request->response_headers()->HasHeader(kChromeManageAccountsHeader)) {
DCHECK(switches::IsNewProfileManagement() &&
- !io_data->is_incognito());
+ !io_data->IsOffTheRecord());
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(ShowAvatarBubbleUIThread, child_id, route_id));
diff --git a/chrome/browser/ui/app_list/test/fake_profile.cc b/chrome/browser/ui/app_list/test/fake_profile.cc
index ca09999..36277cd 100644
--- a/chrome/browser/ui/app_list/test/fake_profile.cc
+++ b/chrome/browser/ui/app_list/test/fake_profile.cc
@@ -17,6 +17,10 @@ std::string FakeProfile::GetProfileName() {
return name_;
}
+Profile::ProfileType FakeProfile::GetProfileType() const {
+ return REGULAR_PROFILE;
+}
+
base::FilePath FakeProfile::GetPath() const {
return path_;
}
diff --git a/chrome/browser/ui/app_list/test/fake_profile.h b/chrome/browser/ui/app_list/test/fake_profile.h
index 615ed6c..eee7499 100644
--- a/chrome/browser/ui/app_list/test/fake_profile.h
+++ b/chrome/browser/ui/app_list/test/fake_profile.h
@@ -30,6 +30,7 @@ class FakeProfile : public Profile {
// Profile overrides.
virtual std::string GetProfileName() OVERRIDE;
+ virtual ProfileType GetProfileType() const OVERRIDE;
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate*
diff --git a/chrome/browser/ui/sync/one_click_signin_helper.cc b/chrome/browser/ui/sync/one_click_signin_helper.cc
index cce093b..3a26ed4 100644
--- a/chrome/browser/ui/sync/one_click_signin_helper.cc
+++ b/chrome/browser/ui/sync/one_click_signin_helper.cc
@@ -907,7 +907,7 @@ OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThreadImpl(
// Check for incognito before other parts of the io_data, since those
// members may not be initalized.
- if (io_data->is_incognito())
+ if (io_data->IsOffTheRecord())
return DONT_OFFER;
if (!SigninManager::IsSigninAllowedOnIOThread(io_data))
diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
index ddb28ff..9a752f3 100644
--- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
+++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
@@ -67,9 +67,10 @@ static KeyedService* BuildSigninManagerMock(content::BrowserContext* profile) {
class TestProfileIOData : public ProfileIOData {
public:
- TestProfileIOData(bool is_incognito, PrefService* pref_service,
- PrefService* local_state, CookieSettings* cookie_settings)
- : ProfileIOData(is_incognito) {
+ TestProfileIOData(Profile::ProfileType profile_type,
+ PrefService* pref_service, PrefService* local_state,
+ CookieSettings* cookie_settings)
+ : ProfileIOData(profile_type) {
// Initialize the IO members required for these tests, but keep them on
// this thread since we don't use a background thread here.
google_services_username()->Init(prefs::kGoogleServicesUsername,
@@ -342,7 +343,7 @@ class OneClickSigninHelperIOTest : public OneClickSigninHelperTest {
virtual void SetUp() OVERRIDE;
- TestProfileIOData* CreateTestProfileIOData(bool is_incognito);
+ TestProfileIOData* CreateTestProfileIOData(Profile::ProfileType profile_type);
protected:
TestingProfileManager testing_profile_manager_;
@@ -365,13 +366,13 @@ void OneClickSigninHelperIOTest::SetUp() {
}
TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData(
- bool is_incognito) {
+ Profile::ProfileType profile_type) {
PrefService* pref_service = profile()->GetPrefs();
PrefService* local_state = g_browser_process->local_state();
CookieSettings* cookie_settings =
CookieSettings::Factory::GetForProfile(profile()).get();
TestProfileIOData* io_data = new TestProfileIOData(
- is_incognito, pref_service, local_state, cookie_settings);
+ profile_type, pref_service, local_state, cookie_settings);
io_data->set_reverse_autologin_pending_email("user@gmail.com");
return io_data;
}
@@ -739,14 +740,16 @@ TEST_F(OneClickSigninHelperTest, RemoveObserverFromProfileSyncService) {
// I/O thread tests
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) {
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
}
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) {
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(true));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::INCOGNITO_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -759,7 +762,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadNoIOData) {
}
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadBadURL) {
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(
OneClickSigninHelper::IGNORE_REQUEST,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
@@ -773,7 +777,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadBadURL) {
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabled) {
EnableOneClick(false);
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -783,7 +788,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadSignedIn) {
PrefService* pref_service = profile()->GetPrefs();
pref_service->SetString(prefs::kGoogleServicesUsername, "user@gmail.com");
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -791,7 +797,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadSignedIn) {
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadEmailNotAllowed) {
SetAllowedUsernamePattern("*@example.com");
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -805,7 +812,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadEmailAlreadyUsed) {
base::UTF8ToUTF16("user@gmail.com"), 0,
std::string());
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -813,7 +821,8 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadEmailAlreadyUsed) {
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadWithRejectedEmail) {
AddEmailToOneClickRejectedList("user@gmail.com");
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
@@ -821,14 +830,16 @@ TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadWithRejectedEmail) {
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadNoSigninCookies) {
AllowSigninCookies(false);
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
}
TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabledByPolicy) {
- scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
+ scoped_ptr<TestProfileIOData> io_data(
+ CreateTestProfileIOData(Profile::REGULAR_PROFILE));
EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
OneClickSigninHelper::CanOfferOnIOThreadImpl(
valid_gaia_url_, &request_, io_data.get()));
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index d110837..13f270e 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -577,6 +577,14 @@ std::string TestingProfile::GetProfileName() {
return profile_name_;
}
+Profile::ProfileType TestingProfile::GetProfileType() const {
+ if (guest_session_)
+ return GUEST_PROFILE;
+ if (force_incognito_ || incognito_)
+ return INCOGNITO_PROFILE;
+ return REGULAR_PROFILE;
+}
+
bool TestingProfile::IsOffTheRecord() const {
return force_incognito_ || incognito_;
}
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index 6e2aeb6..d0771ed 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -223,7 +223,10 @@ class TestingProfile : public Profile {
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
virtual TestingProfile* AsTestingProfile() OVERRIDE;
+
+ // Profile
virtual std::string GetProfileName() OVERRIDE;
+ virtual ProfileType GetProfileType() const OVERRIDE;
// DEPRECATED, because it's fragile to change a profile from non-incognito
// to incognito after the ProfileKeyedServices have been created (some