Chromium Code Reviews| Index: chrome/browser/android/blimp/blimp_contents_profile_attachment.cc |
| diff --git a/chrome/browser/android/blimp/blimp_contents_profile_attachment.cc b/chrome/browser/android/blimp/blimp_contents_profile_attachment.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ca2ba9852fb334e4aadaf673a666e90954864b4 |
| --- /dev/null |
| +++ b/chrome/browser/android/blimp/blimp_contents_profile_attachment.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/supports_user_data.h" |
| +#include "blimp/client/public/blimp_contents.h" |
| + |
| +namespace { |
| +const char kBlimpContentsProfileAttachment[] = |
| + "blimp_contents_profile_attachment"; |
| + |
| +// A holder struct for a Profile that can be used as data. |
| +struct Attachment : public base::SupportsUserData::Data { |
| + public: |
|
Lei Zhang
2016/07/14 23:21:57
Aren't struct members public by default?
nyquist
2016/07/15 17:38:19
Done.
|
| + Profile* profile; |
| +}; |
| + |
| +} // namespace |
| + |
| +namespace chrome { |
| + |
| +void AttachProfileToBlimpContents(blimp::client::BlimpContents* blimp_contents, |
| + Profile* profile) { |
| + DCHECK(profile); |
| + Attachment* attachment = new Attachment; |
| + attachment->profile = profile; |
| + blimp_contents->SetUserData(kBlimpContentsProfileAttachment, attachment); |
| +} |
| + |
| +Profile* GetProfileFromBlimpContents( |
| + blimp::client::BlimpContents* blimp_contents) { |
| + Attachment* attachment = static_cast<Attachment*>( |
| + blimp_contents->GetUserData(kBlimpContentsProfileAttachment)); |
| + DCHECK(attachment); |
| + return attachment->profile; |
| +} |
| + |
| +} // namespace chrome |