Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / ui / tabs / tab_discard_state.cc
blob7a7e8f05592e7e53ab1f097f6cbd95f17e81544c
1 // Copyright 2015 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/ui/tabs/tab_discard_state.h"
7 #include "content/public/browser/web_contents.h"
9 using content::WebContents;
11 namespace {
13 const char kDiscardStateKey[] = "TabDiscardState";
15 } // namespace
17 // static
18 TabDiscardState* TabDiscardState::Get(WebContents* web_contents) {
19 TabDiscardState* discard_state = static_cast<TabDiscardState*>(
20 web_contents->GetUserData(&kDiscardStateKey));
22 // If this function is called, we probably need to query/change the discard
23 // state. Let's go ahead a add one.
24 if (!discard_state) {
25 discard_state = new TabDiscardState;
26 web_contents->SetUserData(&kDiscardStateKey, discard_state);
29 return discard_state;
32 // static
33 void TabDiscardState::Set(WebContents* web_contents, TabDiscardState* state) {
34 web_contents->SetUserData(&kDiscardStateKey, state);
37 // static
38 bool TabDiscardState::IsDiscarded(WebContents* web_contents) {
39 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
40 return discard_state->is_discarded_;
43 // static
44 void TabDiscardState::SetDiscardState(WebContents* web_contents, bool state) {
45 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
46 discard_state->is_discarded_ = state;
49 // static
50 int TabDiscardState::DiscardCount(WebContents* web_contents) {
51 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
52 return discard_state->discard_count_;
55 // static
56 void TabDiscardState::IncrementDiscardCount(WebContents* web_contents) {
57 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
58 discard_state->discard_count_++;
61 // static
62 void TabDiscardState::CopyState(content::WebContents* old_contents,
63 content::WebContents* new_contents) {
64 TabDiscardState* old_state = Get(old_contents);
65 TabDiscardState* new_State = Get(new_contents);
66 *new_State = *old_state;