Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ui/tabs/tab_discard_state.cc

Issue 1332003002: Add option to disallow the discarding of a tab that was previously discarded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky@ comments + fix tests. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/tabs/tab_discard_state.h"
6
7 #include "content/public/browser/web_contents.h"
8
9 using content::WebContents;
10
11 namespace {
12
13 const char kDiscardStateKey[] = "TabDiscardState";
14
15 } // namespace
16
17 // static
18 TabDiscardState* TabDiscardState::Get(WebContents* web_contents) {
19 TabDiscardState* discard_state = static_cast<TabDiscardState*>(
20 web_contents->GetUserData(&kDiscardStateKey));
21
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);
27 }
28
29 return discard_state;
30 }
31
32 // static
33 void TabDiscardState::Set(WebContents* web_contents, TabDiscardState* state) {
34 web_contents->SetUserData(&kDiscardStateKey, state);
35 }
36
37 // static
38 bool TabDiscardState::IsDiscarded(WebContents* web_contents) {
39 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
40 return discard_state->is_discarded_;
41 }
42
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;
47 }
48
49 // static
50 int TabDiscardState::DiscardCount(WebContents* web_contents) {
51 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
52 return discard_state->discard_count_;
53 }
54
55 // static
56 void TabDiscardState::IncrementDiscardCount(WebContents* web_contents) {
57 TabDiscardState* discard_state = TabDiscardState::Get(web_contents);
58 discard_state->discard_count_++;
59 }
60
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;
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698