Skip to content

Commit

Permalink
Introduce ChromeBrowserState interface
Browse files Browse the repository at this point in the history
The ChromeBrowserState interface will serve as iOS's alternative to
Profile.

BUG=436897

Review URL: https://codereview.chromium.org/748853005

Cr-Commit-Position: refs/heads/master@{#306357}
  • Loading branch information
sdefresne authored and Commit bot committed Dec 2, 2014
1 parent 8e5e035 commit d33ce99
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/ios.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'dependencies': [
'ios_base.gyp:*',
'ios_tests_unit.gyp:*',
'provider/ios_provider_chrome.gyp:*',
'provider/ios_provider_web.gyp:*',
'web/ios_web.gyp:*',
],
Expand Down
22 changes: 22 additions & 0 deletions ios/provider/ios_provider_chrome.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2013 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.
{
'variables': {
'chromium_code': 1,
},
'targets': [
{
'target_name': 'ios_provider_chrome_browser',
'type': 'static_library',
'sources': [
'../public/provider/chrome/browser/browser_state/chrome_browser_state.cc',
'../public/provider/chrome/browser/browser_state/chrome_browser_state.h',
],
'dependencies': [
'../../base/base.gyp:base',
'ios_provider_web.gyp:ios_provider_web',
],
},
],
}
3 changes: 3 additions & 0 deletions ios/public/provider/chrome/browser/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+ios/public/provider/web",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2014 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.

#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"

#include "ios/public/provider/web/web_state.h"

namespace ios {

// static
ChromeBrowserState* ChromeBrowserState::FromBrowserState(
web::BrowserState* browser_state) {
// This is safe; this is the only implementation of BrowserState.
return static_cast<ChromeBrowserState*>(browser_state);
}

} // namespace ios
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2013 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.

#ifndef IOS_PUBLIC_PROVIDER_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_H_
#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_H_

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ios/web/public/browser_state.h"

class PrefService;

namespace ios {

// This class is a Chrome-specific extension of the BrowserState interface.
class ChromeBrowserState : public web::BrowserState {
public:
~ChromeBrowserState() override {}

// Returns the ChromeBrowserState corresponding to the given BrowserState.
static ChromeBrowserState* FromBrowserState(BrowserState* browser_state);

// Returns the original "recording" ChromeBrowserState. This method returns
// |this| if the ChromeBrowserState is not incognito.
virtual ChromeBrowserState* GetOriginalChromeBrowserState() = 0;

// Returns the incognito version of this ChromeBrowserState. The returned
// ChromeBrowserState instance is owned by this ChromeBrowserState instance.
// WARNING: This will create the OffTheRecord ChromeBrowserState if it
// doesn't already exist.
virtual ChromeBrowserState* GetOffTheRecordChromeBrowserState() = 0;

// Destroys the OffTheRecord ChromeBrowserState that is associated with this
// ChromeBrowserState, if one exists.
virtual void DestroyOffTheRecordChromeBrowserState() = 0;

// Retrieves a pointer to the PrefService that manages the preferences.
virtual PrefService* GetPrefs() = 0;

protected:
ChromeBrowserState() {}

private:
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserState);
};

} // namespace ios

#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_H_

0 comments on commit d33ce99

Please sign in to comment.