[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / net / cookie_store_util.cc
blobb13a70be98e2a7203aee683599c9ea4c0a66b750
1 // Copyright 2014 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.
5 #include "chrome/browser/net/cookie_store_util.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/net/evicted_domain_cookie_counter.h"
10 #include "chrome/common/chrome_constants.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "components/os_crypt/os_crypt.h"
13 #include "content/public/common/content_constants.h"
14 #include "extensions/common/constants.h"
15 #include "net/extras/sqlite/cookie_crypto_delegate.h"
17 namespace chrome_browser_net {
19 net::CookieMonsterDelegate* CreateCookieDelegate(
20 scoped_refptr<net::CookieMonsterDelegate> next_cookie_monster_delegate) {
21 return new EvictedDomainCookieCounter(next_cookie_monster_delegate);
24 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
25 namespace {
27 // Use the operating system's mechanisms to encrypt cookies before writing
28 // them to persistent store. Currently this only is done with desktop OS's
29 // because ChromeOS and Android already protect the entire profile contents.
31 // TODO(bcwhite): Enable on MACOSX -- requires all Cookie tests to call
32 // OSCrypt::UseMockKeychain or will hang waiting for user input.
33 class CookieOSCryptoDelegate : public net::CookieCryptoDelegate {
34 public:
35 bool EncryptString(const std::string& plaintext,
36 std::string* ciphertext) override;
37 bool DecryptString(const std::string& ciphertext,
38 std::string* plaintext) override;
41 bool CookieOSCryptoDelegate::EncryptString(const std::string& plaintext,
42 std::string* ciphertext) {
43 return OSCrypt::EncryptString(plaintext, ciphertext);
46 bool CookieOSCryptoDelegate::DecryptString(const std::string& ciphertext,
47 std::string* plaintext) {
48 return OSCrypt::DecryptString(ciphertext, plaintext);
51 // Using a LazyInstance is safe here because this class is stateless and
52 // requires 0 initialization.
53 base::LazyInstance<CookieOSCryptoDelegate> g_cookie_crypto_delegate =
54 LAZY_INSTANCE_INITIALIZER;
56 } // namespace
58 net::CookieCryptoDelegate* GetCookieCryptoDelegate() {
59 return g_cookie_crypto_delegate.Pointer();
61 #else // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
62 net::CookieCryptoDelegate* GetCookieCryptoDelegate() {
63 return NULL;
65 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
67 } // namespace chrome_browser_net