summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/net/cookie_util.h
blob: 1f21f08c2d29e2b32bca2fb4159543a8538fd478 (plain)
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
// Copyright 2012 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_CHROME_BROWSER_NET_COOKIE_UTIL_H_
#define IOS_CHROME_BROWSER_NET_COOKIE_UTIL_H_

#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "net/cookies/canonical_cookie.h"

namespace base {
class SequencedTaskRunner;
}

namespace ios {
class ChromeBrowserState;
}

namespace net {
class CookieCryptoDelegate;
class CookieStore;
}

namespace cookie_util {

// Configuration for creation of new cookie stores.
struct CookieStoreConfig {
  // Specifies how session cookies are persisted in the backing data store.
  //
  // EPHEMERAL_SESSION_COOKIES specifies session cookies will not be written
  // out in a manner that allows for restoration.
  //
  // RESTORED_SESSION_COOKIES specifies that session cookies are written in a
  // manner that allows for them to be restored if the cookie store is opened
  // again using RESTORED_SESSION_COOKIES.
  enum SessionCookieMode {
    EPHEMERAL_SESSION_COOKIES,
    RESTORED_SESSION_COOKIES
  };

  // Persistent cookie stores can either be CookieMonster or CookieStoreIOS.
  // The CookieMonster is the cross-platform implementation and should be
  // preferred in general.
  // The CookieStoreIOS must be used when the cookie store is accessed by the
  // system through UIWebView. However, note that only one CookieStoreIOS
  // instance can be kept synchronized with the global system cookie store at a
  // time.
  enum CookieStoreType {
    COOKIE_MONSTER,   // CookieMonster backend.
    COOKIE_STORE_IOS  // CookieStoreIOS backend.
  };

  // If |path| is empty, then this specifies an in-memory cookie store.
  // With in-memory cookie stores, |session_cookie_mode| must be
  // EPHEMERAL_SESSION_COOKIES.
  // Note: If |crypto_delegate| is non-null, it must outlive any CookieStores
  // created using this config.
  CookieStoreConfig(const base::FilePath& path,
                    SessionCookieMode session_cookie_mode,
                    CookieStoreType cookie_store_type,
                    net::CookieCryptoDelegate* crypto_delegate);
  ~CookieStoreConfig();

  const base::FilePath path;
  const SessionCookieMode session_cookie_mode;
  const CookieStoreType cookie_store_type;

  // Used to provide encryption hooks for the cookie store. The
  // CookieCryptoDelegate must outlive any cookie store created with this
  // config.
  net::CookieCryptoDelegate* crypto_delegate;
};

// Creates a cookie store wich is internally either a CookieMonster or a
// CookieStoreIOS.
scoped_ptr<net::CookieStore> CreateCookieStore(const CookieStoreConfig& config);

// Returns true if the cookies should be cleared.
// Current implementation returns true if the device has rebooted since the
// last time cookies have been cleared.
bool ShouldClearSessionCookies();

// Clears the session cookies for |browser_state|.
void ClearSessionCookies(ios::ChromeBrowserState* browser_state);

}  // namespace cookie_util

#endif  // IOS_CHROME_BROWSER_NET_COOKIE_UTIL_H_