Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / mandoline / tab / frame_tree.cc
blob0ebbb4e6256a05b86165b2b6bd90e678d294eb26
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 "mandoline/tab/frame_tree.h"
7 #include "mandoline/tab/frame_tree_delegate.h"
8 #include "mandoline/tab/frame_user_data.h"
10 namespace mandoline {
12 FrameTree::FrameTree(mojo::View* view,
13 FrameTreeDelegate* delegate,
14 FrameTreeClient* root_client,
15 scoped_ptr<FrameUserData> user_data)
16 : view_(view),
17 delegate_(delegate),
18 root_(this,
19 view,
20 view->id(),
21 ViewOwnership::DOESNT_OWN_VIEW,
22 root_client,
23 user_data.Pass()),
24 progress_(0.f) {
25 root_.Init(nullptr);
28 FrameTree::~FrameTree() {
31 Frame* FrameTree::CreateAndAddFrame(mojo::View* view,
32 Frame* parent,
33 FrameTreeClient* client,
34 scoped_ptr<FrameUserData> user_data) {
35 return CreateAndAddFrameImpl(view, view->id(), parent, client,
36 user_data.Pass());
39 Frame* FrameTree::CreateOrReplaceFrame(Frame* frame,
40 mojo::View* view,
41 FrameTreeClient* frame_tree_client,
42 scoped_ptr<FrameUserData> user_data) {
43 DCHECK(frame && frame->HasAncestor(&root_));
45 if (frame->view() == view) {
46 // It's important we Swap() here rather than destroy as otherwise the
47 // clients see a destroy followed by a new frame, which confuses html
48 // viewer.
49 DCHECK(frame != &root_);
50 frame->Swap(frame_tree_client, user_data.Pass());
51 return frame;
54 return CreateAndAddFrame(view, frame, frame_tree_client, user_data.Pass());
57 void FrameTree::CreateSharedFrame(Frame* parent, uint32_t frame_id) {
58 mojo::View* frame_view = root_.view()->GetChildById(frame_id);
59 // |frame_view| may be null if the View hasn't been created yet. If this is
60 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
61 CreateAndAddFrameImpl(frame_view, frame_id, parent, nullptr, nullptr);
64 Frame* FrameTree::CreateAndAddFrameImpl(mojo::View* view,
65 uint32_t frame_id,
66 Frame* parent,
67 FrameTreeClient* client,
68 scoped_ptr<FrameUserData> user_data) {
69 Frame* frame = new Frame(this, view, frame_id, ViewOwnership::OWNS_VIEW,
70 client, user_data.Pass());
71 frame->Init(parent);
72 return frame;
75 void FrameTree::LoadingStateChanged() {
76 bool loading = root_.IsLoading();
77 if (delegate_)
78 delegate_->LoadingStateChanged(loading);
81 void FrameTree::ProgressChanged() {
82 int frame_count = 0;
83 double total_progress = root_.GatherProgress(&frame_count);
84 // Make sure the progress bar never runs backwards, even if that means
85 // accuracy takes a hit.
86 progress_ = std::max(progress_, total_progress / frame_count);
87 if (delegate_)
88 delegate_->ProgressChanged(progress_);
91 void FrameTree::FrameNameChanged(Frame* frame) {
92 root_.NotifyFrameNameChanged(frame);
95 } // namespace mandoline