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
;
13 const char kDiscardStateKey
[] = "TabDiscardState";
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.
25 discard_state
= new TabDiscardState
;
26 web_contents
->SetUserData(&kDiscardStateKey
, discard_state
);
33 void TabDiscardState::Set(WebContents
* web_contents
, TabDiscardState
* state
) {
34 web_contents
->SetUserData(&kDiscardStateKey
, state
);
38 bool TabDiscardState::IsDiscarded(WebContents
* web_contents
) {
39 TabDiscardState
* discard_state
= TabDiscardState::Get(web_contents
);
40 return discard_state
->is_discarded_
;
44 void TabDiscardState::SetDiscardState(WebContents
* web_contents
, bool state
) {
45 TabDiscardState
* discard_state
= TabDiscardState::Get(web_contents
);
46 discard_state
->is_discarded_
= state
;
50 int TabDiscardState::DiscardCount(WebContents
* web_contents
) {
51 TabDiscardState
* discard_state
= TabDiscardState::Get(web_contents
);
52 return discard_state
->discard_count_
;
56 void TabDiscardState::IncrementDiscardCount(WebContents
* web_contents
) {
57 TabDiscardState
* discard_state
= TabDiscardState::Get(web_contents
);
58 discard_state
->discard_count_
++;
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
;