提交 8a701198 编写于 作者: J Jason Simmons

Merge pull request #2369 from jason-simmons/refresh_update_snapshot

Add a way to override the snapshot when running an FLX bundle
......@@ -6,18 +6,26 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/message_loop/message_loop.h"
#include "base/task_runner.h"
#include "base/message_loop/message_loop.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
#include "third_party/zlib/contrib/minizip/unzip.h"
namespace mojo {
namespace asset_bundle {
void ZipAssetBundle::Create(
namespace {
void Ignored(bool) {
}
} // namespace
ZipAssetBundle* ZipAssetBundle::Create(
InterfaceRequest<AssetBundle> request,
const base::FilePath& zip_path,
scoped_refptr<base::TaskRunner> worker_runner) {
new ZipAssetBundle(request.Pass(), zip_path, worker_runner.Pass());
return new ZipAssetBundle(request.Pass(), zip_path, worker_runner.Pass());
}
ZipAssetBundle::ZipAssetBundle(
......@@ -32,12 +40,27 @@ ZipAssetBundle::ZipAssetBundle(
ZipAssetBundle::~ZipAssetBundle() {
}
void ZipAssetBundle::AddOverlayFile(const std::string& asset_name,
const base::FilePath& file_path) {
overlay_files_.insert(std::make_pair(String(asset_name), file_path));
}
void ZipAssetBundle::GetAsStream(
const String& asset_name,
const Callback<void(ScopedDataPipeConsumerHandle)>& callback) {
DataPipe pipe;
callback.Run(pipe.consumer_handle.Pass());
auto overlay = overlay_files_.find(asset_name);
if (overlay != overlay_files_.end()) {
common::CopyFromFile(overlay->second,
pipe.producer_handle.Pass(),
0,
worker_runner_.get(),
base::Bind(&Ignored));
return;
}
ZipAssetHandler* handler = new ZipAssetHandler(
zip_path_,
asset_name.To<std::string>(),
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include "base/task_runner.h"
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
......@@ -18,9 +20,9 @@ namespace asset_bundle {
// ZIP archive.
class ZipAssetBundle : public AssetBundle {
public:
static void Create(InterfaceRequest<AssetBundle> request,
const base::FilePath& zip_path,
scoped_refptr<base::TaskRunner> worker_runner);
static ZipAssetBundle* Create(InterfaceRequest<AssetBundle> request,
const base::FilePath& zip_path,
scoped_refptr<base::TaskRunner> worker_runner);
~ZipAssetBundle() override;
// AssetBundle implementation
......@@ -28,6 +30,10 @@ class ZipAssetBundle : public AssetBundle {
const String& asset_name,
const Callback<void(ScopedDataPipeConsumerHandle)>& callback) override;
// Serve this asset from another file instead of using the ZIP contents.
void AddOverlayFile(const std::string& asset_name,
const base::FilePath& file_path);
private:
ZipAssetBundle(InterfaceRequest<AssetBundle> request,
const base::FilePath& zip_path,
......@@ -36,6 +42,7 @@ class ZipAssetBundle : public AssetBundle {
StrongBinding<AssetBundle> binding_;
const base::FilePath zip_path_;
scoped_refptr<base::TaskRunner> worker_runner_;
std::map<String, base::FilePath> overlay_files_;
DISALLOW_COPY_AND_ASSIGN(ZipAssetBundle);
};
......@@ -46,9 +53,9 @@ class ZipAssetHandler {
public:
ZipAssetHandler(const base::FilePath& zip_path,
const std::string& asset_name,
ScopedDataPipeProducerHandle producer,
scoped_refptr<base::TaskRunner> worker_runner);
const std::string& asset_name,
ScopedDataPipeProducerHandle producer,
scoped_refptr<base::TaskRunner> worker_runner);
~ZipAssetHandler();
void Start();
......
......@@ -55,4 +55,8 @@ interface SkyEngine {
RunFromBundle(string path);
RunFromAssetBundle(string url, mojo.asset_bundle.AssetBundle bundle);
// Run the app from a bundle, but obtain the snapshot from snapshot_path
// instead of using the snapshot within the bundle.
RunFromBundleAndSnapshot(string bundle_path, string snapshot_path);
};
......@@ -305,7 +305,7 @@ public class PlatformViewAndroid extends SurfaceView
mServiceProvider = new PlatformServiceProvider(core, getContext(), localRegistry);
}
void runFromBundle(String path) {
void runFromBundle(String bundlePath, String snapshotPath) {
if (mServiceProvider != null) {
mServiceProvider.close();
......@@ -330,7 +330,11 @@ public class PlatformViewAndroid extends SurfaceView
resetAccessibilityTree();
mSkyEngine.runFromBundle(path);
if (snapshotPath != null) {
mSkyEngine.runFromBundleAndSnapshot(bundlePath, snapshotPath);
} else {
mSkyEngine.runFromBundle(bundlePath);
}
}
private static native long nativeAttach(int inputObserverHandle);
......
......@@ -141,7 +141,7 @@ public class SkyActivity extends Activity {
File dataDir = new File(PathUtils.getDataDirectory(this));
File appBundle = new File(dataDir, SkyApplication.APP_BUNDLE);
if (appBundle.exists()) {
mView.runFromBundle(appBundle.getPath());
mView.runFromBundle(appBundle.getPath(), null);
return;
}
}
......@@ -154,7 +154,8 @@ public class SkyActivity extends Activity {
String action = intent.getAction();
if (Intent.ACTION_RUN.equals(action)) {
mView.runFromBundle(intent.getDataString());
mView.runFromBundle(intent.getDataString(),
intent.getStringExtra("snapshot"));
String route = intent.getStringExtra("route");
if (route != null)
mView.getEngine().pushRoute(route);
......@@ -164,16 +165,6 @@ public class SkyActivity extends Activity {
return false;
}
public boolean loadBundleByName(String name) {
File dataDir = new File(PathUtils.getDataDirectory(this));
File bundle = new File(dataDir, name);
if (!bundle.exists()) {
return false;
}
mView.runFromBundle(bundle.getPath());
return true;
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
......
......@@ -244,6 +244,25 @@ void Engine::RunFromAssetBundle(const mojo::String& url,
weak_factory_.GetWeakPtr(), url_str));
}
void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path,
const mojo::String& snapshot_path) {
TRACE_EVENT0("flutter", "Engine::RunFromBundleAndSnapshot");
std::string bundle_path_str = bundle_path;
ZipAssetBundle* asset_bundle = ZipAssetBundle::Create(
mojo::GetProxy(&root_bundle_),
base::FilePath(bundle_path_str),
base::WorkerPool::GetTaskRunner(true));
std::string snapshot_path_str = snapshot_path;
asset_bundle->AddOverlayFile(kSnapshotKey,
base::FilePath(snapshot_path_str));
root_bundle_->GetAsStream(kSnapshotKey,
base::Bind(&Engine::RunFromSnapshotStream,
weak_factory_.GetWeakPtr(),
bundle_path_str));
}
void Engine::PushRoute(const mojo::String& route) {
if (sky_view_)
sky_view_->PushRoute(route);
......
......@@ -67,6 +67,8 @@ class Engine : public UIDelegate,
void RunFromBundle(const mojo::String& path) override;
void RunFromAssetBundle(const mojo::String& url,
mojo::asset_bundle::AssetBundlePtr bundle) override;
void RunFromBundleAndSnapshot(const mojo::String& bundle_path,
const mojo::String& snapshot_path) override;
void PushRoute(const mojo::String& route) override;
void PopRoute() override;
void OnAppLifecycleStateChanged(sky::AppLifecycleState state) override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册