forked from adamlaska/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookie_change_notifier.cc
More file actions
65 lines (48 loc) · 1.94 KB
/
cookie_change_notifier.cc
File metadata and controls
65 lines (48 loc) · 1.94 KB
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
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/cookie_change_notifier.h"
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/cookies/canonical_cookie.h"
#include "shell/browser/electron_browser_context.h"
using content::BrowserThread;
namespace electron {
CookieChangeNotifier::CookieChangeNotifier(
ElectronBrowserContext* browser_context)
: browser_context_(browser_context), receiver_(this) {
StartListening();
}
CookieChangeNotifier::~CookieChangeNotifier() = default;
base::CallbackListSubscription
CookieChangeNotifier::RegisterCookieChangeCallback(
const base::RepeatingCallback<void(const net::CookieChangeInfo& change)>&
cb) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return cookie_change_sub_list_.Add(cb);
}
void CookieChangeNotifier::StartListening() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!receiver_.is_bound());
network::mojom::CookieManager* cookie_manager =
browser_context_->GetDefaultStoragePartition()
->GetCookieManagerForBrowserProcess();
// Cookie manager should be created whenever network context is created,
// if this fails then there is something wrong with our context creation
// cycle.
CHECK(cookie_manager);
cookie_manager->AddGlobalChangeListener(receiver_.BindNewPipeAndPassRemote());
receiver_.set_disconnect_handler(base::BindOnce(
&CookieChangeNotifier::OnConnectionError, base::Unretained(this)));
}
void CookieChangeNotifier::OnConnectionError() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
receiver_.reset();
StartListening();
}
void CookieChangeNotifier::OnCookieChange(const net::CookieChangeInfo& change) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
cookie_change_sub_list_.Notify(change);
}
} // namespace electron