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 "chrome/browser/extensions/app_data_migrator.h" | 5 #include "chrome/browser/extensions/app_data_migrator.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 extensions::Extension::GetBaseURLFromExtensionId(extension->id()); | 73 extensions::Extension::GetBaseURLFromExtensionId(extension->id()); |
74 | 74 |
75 old_indexed_db_context->CopyOriginData(extension_url, indexed_db_context); | 75 old_indexed_db_context->CopyOriginData(extension_url, indexed_db_context); |
76 } | 76 } |
77 | 77 |
78 void MigrateFileSystem(WeakPtr<extensions::AppDataMigrator> migrator, | 78 void MigrateFileSystem(WeakPtr<extensions::AppDataMigrator> migrator, |
79 StoragePartition* old_partition, | 79 StoragePartition* old_partition, |
80 StoragePartition* current_partition, | 80 StoragePartition* current_partition, |
81 const extensions::Extension* extension, | 81 const extensions::Extension* extension, |
82 const base::Closure& reply) { | 82 const base::Closure& reply) { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
84 | 84 |
85 // Since this method is static and it's being run as a closure task, check to | 85 // Since this method is static and it's being run as a closure task, check to |
86 // make sure the calling object is still around. | 86 // make sure the calling object is still around. |
87 if (!migrator.get()) { | 87 if (!migrator.get()) { |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 FileSystemContext* old_fs_context = old_partition->GetFileSystemContext(); | 91 FileSystemContext* old_fs_context = old_partition->GetFileSystemContext(); |
92 FileSystemContext* fs_context = current_partition->GetFileSystemContext(); | 92 FileSystemContext* fs_context = current_partition->GetFileSystemContext(); |
93 | 93 |
94 // Perform the file system migration on the old file system's | 94 // Perform the file system migration on the old file system's |
95 // sequenced task runner. This is to ensure it queues after any | 95 // sequenced task runner. This is to ensure it queues after any |
96 // in-flight file system operations. After it completes, it should | 96 // in-flight file system operations. After it completes, it should |
97 // invoke the original callback passed into DoMigrationAndReply. | 97 // invoke the original callback passed into DoMigrationAndReply. |
98 old_fs_context->default_file_task_runner()->PostTaskAndReply( | 98 old_fs_context->default_file_task_runner()->PostTaskAndReply( |
99 FROM_HERE, | 99 FROM_HERE, |
100 base::Bind(&MigrateOnFileSystemThread, make_scoped_refptr(old_fs_context), | 100 base::Bind(&MigrateOnFileSystemThread, make_scoped_refptr(old_fs_context), |
101 make_scoped_refptr(fs_context), make_scoped_refptr(extension)), | 101 make_scoped_refptr(fs_context), make_scoped_refptr(extension)), |
102 reply); | 102 reply); |
103 } | 103 } |
104 | 104 |
105 void MigrateLegacyPartition(WeakPtr<extensions::AppDataMigrator> migrator, | 105 void MigrateLegacyPartition(WeakPtr<extensions::AppDataMigrator> migrator, |
106 StoragePartition* old_partition, | 106 StoragePartition* old_partition, |
107 StoragePartition* current_partition, | 107 StoragePartition* current_partition, |
108 const extensions::Extension* extension, | 108 const extensions::Extension* extension, |
109 const base::Closure& reply) { | 109 const base::Closure& reply) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 | 111 |
112 IndexedDBContext* indexed_db_context = | 112 IndexedDBContext* indexed_db_context = |
113 current_partition->GetIndexedDBContext(); | 113 current_partition->GetIndexedDBContext(); |
114 IndexedDBContext* old_indexed_db_context = | 114 IndexedDBContext* old_indexed_db_context = |
115 old_partition->GetIndexedDBContext(); | 115 old_partition->GetIndexedDBContext(); |
116 | 116 |
117 // Create a closure for the file system migration. This is the next step in | 117 // Create a closure for the file system migration. This is the next step in |
118 // the migration flow after the IndexedDB migration. | 118 // the migration flow after the IndexedDB migration. |
119 base::Closure migrate_fs = | 119 base::Closure migrate_fs = |
120 base::Bind(&MigrateFileSystem, migrator, old_partition, current_partition, | 120 base::Bind(&MigrateFileSystem, migrator, old_partition, current_partition, |
(...skipping 21 matching lines...) Expand all Loading... |
142 } | 142 } |
143 | 143 |
144 bool AppDataMigrator::NeedsMigration(const Extension* old, | 144 bool AppDataMigrator::NeedsMigration(const Extension* old, |
145 const Extension* extension) { | 145 const Extension* extension) { |
146 return old && old->is_legacy_packaged_app() && extension->is_platform_app(); | 146 return old && old->is_legacy_packaged_app() && extension->is_platform_app(); |
147 } | 147 } |
148 | 148 |
149 void AppDataMigrator::DoMigrationAndReply(const Extension* old, | 149 void AppDataMigrator::DoMigrationAndReply(const Extension* old, |
150 const Extension* extension, | 150 const Extension* extension, |
151 const base::Closure& reply) { | 151 const base::Closure& reply) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 152 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
153 DCHECK(NeedsMigration(old, extension)); | 153 DCHECK(NeedsMigration(old, extension)); |
154 | 154 |
155 // This should retrieve the general storage partition. | 155 // This should retrieve the general storage partition. |
156 content::StoragePartition* old_partition = | 156 content::StoragePartition* old_partition = |
157 BrowserContext::GetStoragePartitionForSite( | 157 BrowserContext::GetStoragePartitionForSite( |
158 profile_, Extension::GetBaseURLFromExtensionId(extension->id())); | 158 profile_, Extension::GetBaseURLFromExtensionId(extension->id())); |
159 | 159 |
160 // Enable the new extension so we can access its storage partition. | 160 // Enable the new extension so we can access its storage partition. |
161 bool old_was_disabled = registry_->AddEnabled(extension); | 161 bool old_was_disabled = registry_->AddEnabled(extension); |
162 | 162 |
163 // This should create a new isolated partition for the new version of the | 163 // This should create a new isolated partition for the new version of the |
164 // extension. | 164 // extension. |
165 StoragePartition* new_partition = BrowserContext::GetStoragePartitionForSite( | 165 StoragePartition* new_partition = BrowserContext::GetStoragePartitionForSite( |
166 profile_, Extension::GetBaseURLFromExtensionId(extension->id())); | 166 profile_, Extension::GetBaseURLFromExtensionId(extension->id())); |
167 | 167 |
168 // Now, restore the enabled/disabled state of the new and old extensions. | 168 // Now, restore the enabled/disabled state of the new and old extensions. |
169 if (old_was_disabled) | 169 if (old_was_disabled) |
170 registry_->RemoveEnabled(extension->id()); | 170 registry_->RemoveEnabled(extension->id()); |
171 else | 171 else |
172 registry_->AddEnabled(old); | 172 registry_->AddEnabled(old); |
173 | 173 |
174 MigrateLegacyPartition(weak_factory_.GetWeakPtr(), old_partition, | 174 MigrateLegacyPartition(weak_factory_.GetWeakPtr(), old_partition, |
175 new_partition, extension, reply); | 175 new_partition, extension, reply); |
176 } | 176 } |
177 | 177 |
178 } // namespace extensions | 178 } // namespace extensions |
OLD | NEW |