Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "mandoline/tab/frame.h" | 5 #include "mandoline/tab/frame.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" | 
| 10 #include "components/view_manager/public/cpp/view.h" | 10 #include "components/view_manager/public/cpp/view.h" | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 *services = GetProxy(&services_).Pass(); | 36 *services = GetProxy(&services_).Pass(); | 
| 37 | 37 | 
| 38 if (exposed_services) { | 38 if (exposed_services) { | 
| 39 mojo::ServiceProviderPtr exposed_services_ptr; | 39 mojo::ServiceProviderPtr exposed_services_ptr; | 
| 40 exposed_services_.Bind(GetProxy(&exposed_services_ptr)); | 40 exposed_services_.Bind(GetProxy(&exposed_services_ptr)); | 
| 41 *exposed_services = exposed_services_ptr.Pass(); | 41 *exposed_services = exposed_services_ptr.Pass(); | 
| 42 } | 42 } | 
| 43 } | 43 } | 
| 44 | 44 | 
| 45 Frame::~Frame() { | 45 Frame::~Frame() { | 
| 46 view_->RemoveObserver(this); | 46 if (view_) | 
| 47 view_->RemoveObserver(this); | |
| 47 STLDeleteElements(&children_); | 48 STLDeleteElements(&children_); | 
| 48 if (parent_) | 49 if (parent_) | 
| 49 parent_->Remove(this); | 50 parent_->Remove(this); | 
| 50 view_->ClearLocalProperty(kFrame); | 51 if (view_) | 
| 52 view_->ClearLocalProperty(kFrame); | |
| 51 if (view_ownership_ == ViewOwnership::OWNS_VIEW) | 53 if (view_ownership_ == ViewOwnership::OWNS_VIEW) | 
| 52 view_->Destroy(); | 54 view_->Destroy(); | 
| 53 } | 55 } | 
| 54 | 56 | 
| 55 // static | 57 // static | 
| 56 Frame* Frame::FindFirstFrameAncestor(View* view) { | 58 Frame* Frame::FindFirstFrameAncestor(View* view) { | 
| 57 while (view && !view->GetLocalProperty(kFrame)) | 59 while (view && !view->GetLocalProperty(kFrame)) | 
| 58 view = view->parent(); | 60 view = view->parent(); | 
| 59 return view ? view->GetLocalProperty(kFrame) : nullptr; | 61 return view ? view->GetLocalProperty(kFrame) : nullptr; | 
| 60 } | 62 } | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 71 DCHECK_EQ(node->parent_, this); | 73 DCHECK_EQ(node->parent_, this); | 
| 72 auto iter = std::find(children_.begin(), children_.end(), node); | 74 auto iter = std::find(children_.begin(), children_.end(), node); | 
| 73 DCHECK(iter != children_.end()); | 75 DCHECK(iter != children_.end()); | 
| 74 node->parent_ = nullptr; | 76 node->parent_ = nullptr; | 
| 75 children_.erase(iter); | 77 children_.erase(iter); | 
| 76 } | 78 } | 
| 77 | 79 | 
| 78 void Frame::OnViewDestroying(mojo::View* view) { | 80 void Frame::OnViewDestroying(mojo::View* view) { | 
| 79 if (parent_) | 81 if (parent_) | 
| 80 parent_->Remove(this); | 82 parent_->Remove(this); | 
| 81 // Assume the view associated with the root is never deleted out from under | |
| 82 // us. | |
| 83 // TODO(sky): this is likely bogus. Change browser to create a child for | |
| 84 // each FrameTree. | |
| 85 DCHECK_NE(this, tree_->root()); | |
| 86 | 83 | 
| 87 // Reset |view_ownership_| so we don't attempt to delete |view_| in the | 84 // Reset |view_ownership_| so we don't attempt to delete |view_| in the | 
| 88 // destructor. | 85 // destructor. | 
| 89 view_ownership_ = ViewOwnership::DOESNT_OWN_VIEW; | 86 view_ownership_ = ViewOwnership::DOESNT_OWN_VIEW; | 
| 87 | |
| 88 // Assume the view associated with the root is never deleted out from under | |
| 89 // us. | |
| 90 // TODO(sky): Change browser to create a child for each FrameTree. | |
| 91 if (tree_->root() == this) { | |
| 
 
Fady Samuel
2015/06/04 03:21:45
Alternatively, FrameTree could hold a weakptr to t
 
jam
2015/06/04 03:51:30
(I'll defer to Scott)
 
 | |
| 92 view_ = nullptr; | |
| 
 
sky
2015/06/04 19:17:50
view_->RemoveObserver(this) before the return
 
jam
2015/06/04 19:20:48
Done.
 
 | |
| 93 return; | |
| 94 } | |
| 95 | |
| 90 delete this; | 96 delete this; | 
| 91 } | 97 } | 
| 92 | 98 | 
| 93 } // namespace mandoline | 99 } // namespace mandoline | 
| OLD | NEW |